UPDATED
I am trying to add new page on front end. I am doing as following. I have a form, where I am using my action to load the view. On button click it never goes to controller, please help me, what I am doing wrong.
My form is as
<div id="abc-category-search">
<form id="abc-category-search-form" method="post" action="<?php echo Mage::getUrl('helloworld') ?>">
<label for="search"><?php echo $this->__('Search by product SKU/Category') ?>:</label>
<input id="abc-category-search-string" name="search" value="" />
<input id="abc-category-search-cat" type="hidden" name="category" value="<?php echo $category; ?>" />
<button id="abc-category-search-submit" type="submit" class="engine-btn" value="" >
<?php echo $this->__('Search') ?>
</button>
</form>
</div>
And I am adding page like this.
app/code/local/Abc/Helloworld/etc/config.xml
<?xml version="1.0"?>
<config>
<global>
<modules>
<Abc_Helloworld>
<version>
0.1.0
</version>
</Abc_Helloworld>
</modules>
<blocks>
<abc_helloworld>
<class>Abc_Helloworld_Block</class>
</abc_helloworld>
</blocks>
</global>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>Abc_Helloworld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
<layout>
<updates>
<helloworld>
<file>abc_helloworld.xml</file>
</helloworld>
</updates>
</layout>
</frontend>
</config>
And
app/code/local/Abc/Helloworld/controllers/IndexController.php
<?php
class Abc_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
And
app/code/local/Abc/Helloworld/Block/Helloworld.php
<?php
class Abc_HelloWorld_Block_Helloworld extends Mage_Core_Block_Template {
// necessary methods
}
And Layout file is
app/design/frontend/default/Jin/layout/abc_helloworld.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<helloworld_index_index>
<reference name="content">
<block type="abc_helloworld/helloWorld" name="helloworld_any_block" template="helloworld/index.phtml" />
</reference>
</helloworld_index_index>
</layout>
And .phtml
app/design/frontend/default/jin/template/helloworld/helloworld.phtml
<div>
<?php
echo 'Abdul Ghaffar';
?>
</div>
Best Answer
Problem resides in your layout update xml file, particularly in the following block declaration.
Magento fails to find this block, because you don't have block declaration in your
config.xml
file. So you need to update your config.xml file with following code:Here you are declaring your block group name. That's it.
If you want to use your own custom block, then the reference to your block will also need to change like this.
Difference here is, I am using
abc_helloworld/helloWorld
instead ofabc_helloworld/index
. This is because your block type reference looks for a blockAbc_HelloWorld_Block_Index
and which is not defined.Also make sure
default/jin
is your current package theme. Otherwise it would be better to move your phtml template file tobase/default
package theme directory since it is the final fallback location for Magento.Make sure you clear all cache after all these changes made. Happy coding
EDIT - 1
Your form action is also need to be changed.
It should be like
Let Magento generate correct URL for you. :)
EDIT - 2
Use below
config.xml
fileMain difference here is, you use
Helloworld
instead ofHelloWorld
in almost all configuration and I also changed router frontname tohelloworld
instead ofHelloworld
.Make sure you have activation file for you module
File :
app\etc\modules\Abc_HelloWorld.xml
FINAL EDIT
Magento is Letter sensitive. Both me and digitalPianism says samething. You are using the file structure
Abc\HelloWorld
. Hence you need to use same naming concept. ieAbc_HelloWorld
. Or if you like to have a class nameAbc_Helloworld
, then your file structure should beAbc/Helloworld
.Now about layout update xml file. You have a template file
helloworld/helloworld.phtml
and hence you need to specify it correctly in your block. ieThis block will generally say 3 things to Magento.
Assumes your module is
Abc_HelloWorld
and notAbc_Helloworld
and your file structure is likeAbc/HelloWorld
My block is of type =
abc_helloworld/helloWorld
. This will be read by Magento likeAbc_HelloWorld_Block_HelloWorld
.My block name is
helloworld_any_block
app\design\frontend\{package}\{theme}\template\helloworld/helloworld.phtml
as my block's template.