We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

$this->EE->load->view() in module?

Development and Programming

Nico Meijer's avatar
Nico Meijer
41 posts
13 years ago
Nico Meijer's avatar Nico Meijer

Hi,

Just checking here: is it still not possible to use view files inside a module (mod.mymod.php)? Just upgraded to 2.5.2.

For instance,

$this->EE->load->view('test')

gives me the white screen of death (regardless of output and debugging settings (so much for error logging thankyouverymuch)) and

$this->EE->load->view(PATH_THIRD.'mymod/views/test')

yields a nicely formatted error on screen:

Unable to load the requested file: /path/to/system/expressionengine/third_party/mymod/views/test.php

which of course is right there.

Any news, hints, tips on this? I really want to get some HTML/CSS/PHP magic done before handing over data to a template.

Thanks… Nico

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
13 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Hi Nico,

…gives me the white screen of death (regardless of output and debugging settings (so much for error logging thankyouverymuch))

Have you checked your error log? Have you tried setting the debug mode in config.php? (this article may help)

In your module file (likely best placed in the constructor) try adding this:

$this->EE->load->add_package_path('mymod');

then go back to your first code example to test.

Erik

       
Nico Meijer's avatar
Nico Meijer
41 posts
13 years ago
Nico Meijer's avatar Nico Meijer

Hi Erik,

Thanks for chiming in!

Have you checked your error log? Have you tried setting the debug mode in config.php? (this article may help)

Yes, I’ve tried all that: no banana. Great article, btw. 😊

In your module file (likely best placed in the constructor) try adding this:
$this->EE->load->add_package_path('mymod');
then go back to your first code example to test.

Mucked about a bit with that and now bingo!

Thanks a bunch!… Nico

       
the3mus1can's avatar
the3mus1can
426 posts
13 years ago
the3mus1can's avatar the3mus1can

Try adding:

$this->EE->load-> add_package_path(PATH_THIRD . 'mymod');

To the constructor.

       
alysiarosenbalm's avatar
alysiarosenbalm
1 posts
2 years ago
alysiarosenbalm's avatar alysiarosenbalm

It is possible to use view files inside a module in ExpressionEngine. To load a view file from within a module, you should use the following code:

$this->EE->load->library(‘view’); $data[‘foo’] = ‘bar’; $view = $this->EE->load->view(‘test’, $data, TRUE);

In this example, the load->library(‘view’) method is used to load the View library, which is required to load the view rooftop snipers file. The second parameter is an array of data that can be passed to the view file, and the third parameter is set to TRUE to tell the load->view() method to return the rendered output instead of sending it to the browser. Make sure that the view file is located in the correct directory within your module, which should be system/expressionengine/third_party/mymod/views/test.php. Also, check that the permissions on the views directory are set correctly. If you’re still experiencing issues, you may want to check the PHP error log or enable debugging in ExpressionEngine to get more information about the error.

       
jimmyjane's avatar
jimmyjane
1 posts
one year ago
jimmyjane's avatar jimmyjane

Hello Nico,

In ExpressionEngine 2.5.2, using view files inside modules is not yet officially supported. This is a limitation of the framework and has been reported by many users.

The main reason you get the “white screen of death” when using $this->EE->load->view(‘test’) is because ExpressionEngine cannot find the requested view file. As for the error “Unable to load the requested file: /path/to/system/expressionengine/third_party/mymod/views/test.php”, this is because ExpressionEngine cannot find the path to the view file you specified.

To solve rice purity score problem, there are some suggestions that you can try using template files instead of view files: You can create template files inside the module and use $this->EE->TMPL->load_partial () to load them. Or instead of using view files directly, you can create a controller for the module and load the view files from there. You can also use the “Module Themes” feature that allows you to create separate themes for modules, including view files.

Hope the above suggestions will help you solve the problem. If you still have questions, please contact me.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.