Magento 1x: Create a controller & xml layout for the module

If you don’t know how to create a module then see this link. Create a Folder controllers in inside your module path: app\code\local\Trenza\Orderimage\ . Now create a IndexController.php and add bellow code in here.

<?php
/*
* Copyright (c) 2015 www.trenzasoft.com
*/
class Trenza_Orderimage_IndexController extends Mage_Core_Controller_Front_Action {
  public function indexAction() {	
		$this->loadLayout();     
		$this->renderLayout();
  }
}

Now need to edit your config page. So go to and edit config.xml like that just add the new code or fully replace the code. In controller it can mirror the layout.

 

<?xml version="1.0"?>
<config>
    <modules>
        <Trenza_Orderimage>
            <version>1.0.0</version>
        </Trenza_Orderimage>
    </modules>
	<frontend>
		<routers>
			<helloworld>
				<use>standard</use>
				<args>
					<module>Trenza_Orderimage</module>
					<frontName>helloworld</frontName>
				</args>
			</helloworld>
		</routers>
		<layout>
			<updates>
				<helloworld>
					<file>trenza/mylayout.xml</file>
				</helloworld>
			</updates>
		</layout>
	</frontend>
</config>

We edit / create config.xml and make our route. Route is the first path name. we create <helloworld> which is the route. So our url will be http://yoursite.com/helloworld . We create IndexController So url will be
http://yoursite.com/routename/controllername/controllerfunctionname/ if you want to pass get id variable then it will be http://yoursite.com/routename/controllername/controllerfunctionname/id/10/customer_id/10 this way we can pass the get variable one by one.

Now we create a simple controller function testAction. test is the function name Action add if you use it as a url. Example if you use test function only for controller inside use then type as function test(). So if you http://yoursite.com/routename/controllername/test it will showing error cause this is not a url usable. If you need it as a url then use function testAction() like that. Now open the url it will work.
Our controller is:

<?php
/*
* Copyright (c) 2015 www.trenzasoft.com
*/
class Trenza_Orderimage_IndexController extends Mage_Core_Controller_Front_Action {
  public function indexAction() {	
		$this->loadLayout();     
		$this->renderLayout();
  }
  
  public function testAction(){
	  echo 'test';
  }
}

Now Need to override layout file. So go to your theme path. app\design\frontend\rwd\default\layout if you don’t know your theme name or anything visit this link for know how to know magento activate theme. I use trenza/mylayout.xml for my layout in config.xml file. So just create a folder trenza now on app\design\frontend\rwd\default\layout\trenza create a mylayout.xml. mylayout.xml:

<?xml version="1.0"?>
<layout version="0.1.0">
	<default>
		<reference name="top.links">
			<action method="addLink" translate="label title" module="prescription">
				<label>My First</label>
				<url>helloworld</url>
				<title>helloworld</title>
				<prepare>true</prepare>
				<urlParams/>
				<position>0</position>
			</action>
		</reference>        
  </default>
  
  <prescription_index_index>
		<reference name="root">
			<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
		</reference>
    <reference name="content">
		<block type="myblock/myblock" name="myblock" template="trenza/myfile.phtml"></block>
    </reference>
  </prescription_index_index>
</layout>

Now we create layout file. Now need to create phtml file. we indicate that file in layout file. go to our template file app\design\frontend\rwd\default\template\trenza here create a file name myfile.phtml and just inside that file type text hello or anything.
Now need to create a block. <block type=”myblock/myblock” name=”prescription” template=”trenza/myfile.phtml”></block> here we called myblock. so now go to your module path and create a Block folder inside there create a Myblock.php. Path: app\code\local\Trenza\Orderimage\Block. Myblock.php :

<?php
/*
* Copyright (c) 2015 www.trenzasoft.com
*/
class Trenza_Prescription_Block_Myblock extends Mage_Core_Block_Template {

    
    public function test() {
		echo 'test';
	}
}

Now go to the url http://yoursite/mag_import_export/helloworld/

 

Leave a Reply