4

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>
  • @Rajeev I have added the module as you said, now it is working, going to controller and loading my view (if I put my new module's url i.e myweb.com/helloworld in url bar), but there is a problem, as you can see in Form I have an action, pointing to my controller, on clicking submit button it go to controller, but url never changes(new Mage::getUrl('helloworld')) is never loaded, can you point me, what could be reason. – Abdul Ghaffar Jun 27 '16 at 4:18
5

Problem resides in your layout update xml file, particularly in the following block declaration.

<block type="abc_helloworld/index" name="helloworld_any_block" template="helloworld/index.phtml" />

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:

<config>
    <global>
        <blocks>
            <abc_helloworld>
                <class>Abc_HelloWorld_Block</class>
            </abc_helloworld>
        </blocks>
    </global>
</config>

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.

<block type="abc_helloworld/helloWorld" name="helloworld_any_block" template="helloworld/index.phtml" />

Difference here is, I am using abc_helloworld/helloWorld instead of abc_helloworld/index. This is because your block type reference looks for a block Abc_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 to base/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

<form id="abc-category-search-form" method="post" action="<?php echo Mage::getUrl('helloworld') ?>">

Let Magento generate correct URL for you. :)

EDIT - 2

Use below config.xml file

<?xml version="1.0"?>
    <config>
        <modules>
            <Abc_HelloWorld>
                <version>0.1.0</version>
            </Abc_HelloWorld>
        </modules>
        <global>
            <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>

Main difference here is, you use Helloworld instead of HelloWorld in almost all configuration and I also changed router frontname to helloworld instead of Helloworld.

Make sure you have activation file for you module

File : app\etc\modules\Abc_HelloWorld.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Abc_HelloWorld>
            <active>true</active>
            <codePool>local</codePool>
        </Abc_HelloWorld>
    </modules>
</config>

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. ie Abc_HelloWorld. Or if you like to have a class name Abc_Helloworld, then your file structure should be Abc/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. ie

<block type="abc_helloworld/helloWorld" name="helloworld_any_block" template="helloworld/helloworld.phtml" />

This block will generally say 3 things to Magento.

Assumes your module is Abc_HelloWorld and not Abc_Helloworld and your file structure is like Abc/HelloWorld

  1. My block is of type = abc_helloworld/helloWorld. This will be read by Magento like Abc_HelloWorld_Block_HelloWorld.

  2. My block name is helloworld_any_block

  3. Use app\design\frontend\{package}\{theme}\template\helloworld/helloworld.phtml as my block's template.
| improve this answer | |
  • I have followed you, but no success – Abdul Ghaffar Jun 20 '16 at 8:06
  • please update your qn with updated files and let me know – Rajeev K Tomy Jun 20 '16 at 8:08
  • you also need to update layout section in config.xml as digital pianism indicated. – Rajeev K Tomy Jun 20 '16 at 8:10
  • I have updated the post, please have a look on it. (can you refer me to some other page) – Abdul Ghaffar Jun 20 '16 at 8:58
  • @AbdulGhaffar see my edit-2 – Rajeev K Tomy Jun 20 '16 at 9:09
1

The problem in your case is that your form is not calling the right action.

The front name you declare in your config.xml is the following: Helloworld (by the way, I suggest you change it to helloworld ).

So your form action should be helloworld/index/index instead of abc_helloWorld/index/index

On top of that your frontend layout declaration is missing the filename type.

Instead of:

    <layout>
        <updates>
            <helloworld>
                <file>abc_helloworld</file>
            </helloworld>
        </updates>
    </layout>

It should be:

    <layout>
        <updates>
            <helloworld>
                <file>abc_helloworld.xml</file>
            </helloworld>
        </updates>
    </layout>

Finally, your blocks are not declared at all. You should the following under the <config> tag of your config.xml :

<global>
    <blocks>
        <abc_helloworld>
            <class>Abc_Helloworld_Block</class>
        </abc_helloworld>
    </blocks>
</global>

Last point, I reckon you have a problem with your module folder.

Indeed, the module name is declared in your config.xml as Abc_Helloworld but your folder are declared as:

app/code/local/Abc/HelloWorld

You should change it to:

app/code/local/Abc/Helloworld

And change your classes accordingly.

| improve this answer | |
  • Same result, nothing is changed – Abdul Ghaffar Jun 20 '16 at 7:52
  • @AbdulGhaffar see my update – Raphael at Digital Pianism Jun 20 '16 at 7:56
  • I have followed you, but no success – Abdul Ghaffar Jun 20 '16 at 8:06
  • I have updated the post, please have a look on it. (can you refer me to some other page) – Abdul Ghaffar Jun 20 '16 at 8:58
  • @AbdulGhaffar see my update. Also try to change <frontName>Helloworld</frontName> to <frontName>helloworld</frontName> – Raphael at Digital Pianism Jun 20 '16 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.