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

Loading views from a core module file loading view from wrong location

Development and Programming

Christopher Imrie's avatar
Christopher Imrie
57 posts
16 years ago
Christopher Imrie's avatar Christopher Imrie

Hi guys, I am running latest build of EE 2.0.1 (20100215) and I noticed some funkiness when loading a view from a core module file (ie mod.filename.php). The view loader attempts to find the specified view from inside the /system/expressionengine/views/ folder, as opposed the module’s own view folder in the /system/expressionengine/third_party/module_name/views/.

The public_beta docs say that the when the module control panel files (mcp.filename.php) load a view it will grab the specified view from the third_party/module_name/views/ folder. Currently this functionality is not happening when loading from a core module file, and I am guessing it should be.

At the moment, the only workaround for this is to backtrack and work your way to the correct file like so:

echo $this->EE->load->view('../third_party/module_name/views/index', $data);
       
Greg Aker's avatar
Greg Aker
6,022 posts
16 years ago
Greg Aker's avatar Greg Aker

Christopher,

I’m moving this down to the Modules forums, as it’s a better fit.

You don’t echo your view from the module controller. In the case of a module, you return the load.

So try:

function index()
{
   $vars['cp_page_title'] = $this->EE->lang->line('module_title');

   // Some other code

   return $this->EE->load->view('index', $vars, TRUE);
}

Let us know if that helps.

-greg

       
Christopher Imrie's avatar
Christopher Imrie
57 posts
16 years ago
Christopher Imrie's avatar Christopher Imrie

HI Greg, Apologies, the code I included in my post above is wrong, I know I’m not supposed to echo out the view. My bad.

The problem persists though. I normally just call the load view function without returning it, but I changed my code to return the load view function, but the same problem remains.

Calling $this->EE->load->view(‘index’) from mod.my_module.php tries to load the specified view from system/expressionengine/views/ not the module’s own views folder found in system/expressionengine/third_party/my_module/views/

bug?

       
Greg Aker's avatar
Greg Aker
6,022 posts
16 years ago
Greg Aker's avatar Greg Aker

Christopher, I’m not thinking so, as I have several modules sitting in my third_party folder that load fine.

The loader is going to look for the file in several places. What exact error are you receiving, and are you making sure to put the third parameter on load call like I have above?

       
Christopher Imrie's avatar
Christopher Imrie
57 posts
16 years ago
Christopher Imrie's avatar Christopher Imrie

I may have not mentioned something that is probably why we are getting our lines crossed.

My module’s method is being called as an action reference in the url (ie index.php?ACT=32). So its not being called by a tag in the templates.

I have tried setting the third parameter to true to return it as a string, but still no luck.

UPDATE: Screenshot of the error attached.

       
Greg Aker's avatar
Greg Aker
6,022 posts
16 years ago
Greg Aker's avatar Greg Aker

ah okay, so we’re on the same page, what exactly is the goal of your module here? Are you trying to load a module view on the front end, or are you trying to load this on the back end?

       
Christopher Imrie's avatar
Christopher Imrie
57 posts
16 years ago
Christopher Imrie's avatar Christopher Imrie

I am using the module as a secure endpoint for some ajax requests I am making whilst the user is on the publish page. I am using the users current session XID to secure the requests and make sure the module can only be fired up by a logged in user. All the module does is provide json data for the ajax request.

The fieldtype/module in question is here: http://ellislab.com/forums/viewthread/146369/

It is fully working, and currently being beta tested so I can send you a copy if you want to have a look.

When the module is called by an action, simply echoing out the response from the method results in an error (php, headers already sent error) so I have to use a view. So when I started trying to get the view loading I found that EE was looking in the wrong place.

       
Greg Aker's avatar
Greg Aker
6,022 posts
16 years ago
Greg Aker's avatar Greg Aker

Ah okay, makes perfect sense.

the ACT requests are mainly for front end functions. So, if you’re submitting on the publish page via jquery, you can do something like:

$.ajax({
  type:     "POST",
  dataType: 'json',
  url:      EE.BASE+"&C=addons_modules&M=show_module_cp&module=your_module&method=some_ajax_method_being_called",
  // More code here:
});

Then, in the method you submit to, do what you need to do and then exit with something like:

$resp['some_message'] = 'something';
   $this->EE->output->send_ajax_response($resp);

output->send_ajax_response() will send json for you. 😊

-greg

       
Christopher Imrie's avatar
Christopher Imrie
57 posts
16 years ago
Christopher Imrie's avatar Christopher Imrie

Haha! Cracking !

I had no idea EE had an inbuilt ajax response method, but now that I think about it EE2 is loaded with autosaving & js notification, so of course it would make sense to have one.

Cheers Greg, just the thing I needed.

       

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.