Reputation: 1762
Given the class
<?php
class NameSpace_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action
{
public function sayHelloAction()
{
}
}
What should be the name of the layout file?
hello_world.xml
helloworld.xml
What should be the xml action name of the sayHelloAction?
<hello_world_index_say_hello></hello_world_index_say_hello>
<helloworld_index_sayhello>
An article on magento naming conventions would be appreciated. The examples I found only explaned the Namespace_Helloworld_IndexController::sayhello() coding style.
Upvotes: 2
Views: 3241
Reputation: 166066
What should be the name of the layout file?
Anything you want. There's no enforced naming convention for the layout file — it's completely decoupled from the module name. All you need to do is specify an XML layout file name in your config.xml
file. That said, the convention among the more engineering focused Magento developers is to use a lowercased version of the full module name for third party modules (namespace_helloworld.xml
).
What should be the xml action name of the sayHelloAction?
The correct name for this node is the full action handle. The naming here is going to depend on how you configured your router nodes in config.xml
, and how a particular URL routed itself through the system. In other words, beyond the scope of a single Stack Overflow answer.
You can peek at the full action name with the following code in your action method.
public function sayHelloAction()
{
var_dump(strToLower($this->getFullActionName()));
}
Generally speaking though, the convention is
[Route Name]_[Controller Name]_[Action Name]
Assuming you setup your route name to match your module name, that would be
route name: namespace_helloworld
controller name: index
action name: sayHello
or
namespace_helloworld_index_sayhello
Upvotes: 5
Reputation: 69
NameSpace_HelloWorld_IndexControllerfile is incorrect controller class name controller class name should be ended by 'Controller', Controllerfile is not allowed
about layout file: you should define the name of layout file in config.php
about handlers: if you use camelCase, you just need to lowercase the method name and remove 'action' from the end, for example getSuperDataAction will be < route>_< controller>_getsuperdata
Upvotes: 0