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
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
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:then go back to your first code example to test.$this->EE->load->add_package_path('mymod');
Mucked about a bit with that and now bingo!
Thanks a bunch!… Nico
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.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.