Zac
Zac

Reputation: 12836

Create a php file within the module

In magento I have started to set up an admin module and am not using layout XML but rather just the indexController to load my phtml.

 public function indexAction()
 {
   $this->loadLayout();
   $this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('module/page1.phtml'));
   // ...

From that phtml file I need to query another php file but I don't understand how I can add another file and what the path would be to page2.phtml ? So I just need a home for this other php file. It can really be anywhere on the server.

For example from my index I am loading a script that runs Ajax on another php file. How can I add that somewhere inside the module and what would the url be to it. This whole controller business has me pretty confused. I am tired and hoping to wake up to a bounty of stack overflow wisdom. My apologies if this question is not very clear. I will edit tomorrow after some coffee if need be.

Upvotes: 1

Views: 144

Answers (1)

John Watson
John Watson

Reputation: 2573

In Magento, URLs are not paths to phtml files (which are just templates), they are paths to controllers and actions. A URL is comprised of the "frontname" (a reference to the module), then the controller, then the action. The partial code you've shown is the index action (the default action) for your controller. The target of your Ajax call will be another action probably in the same controller. That action can then use the technique you've used above to load the appropriate template phtml file (page2.phtml).

Upvotes: 3

Related Questions