在 magento admin 中从一个控制器创建多个页面
我可以在 Magento 管理中使用该控制器加载一页,在本例中,该页面位于 app/code/local/me/one/IndexController.php
中:
public function indexAction()
{
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('one/one.phtml'));
}
并且我创建了菜单在 config.xml 中包含此内容
<adminhtml>
<menu>
<catalog>
<children>
<one_menu translate="title" module="foo">
<title>TEST</title>
<children>
<list translate="title" module="foo">
<title>one</title>
<action>one/index/index</action>
</list>
<new translate="title" module="foo">
<title>two</title>
<action>two/index/index</action>
</new>
</children>
</one_menu>
</children>
</catalog>
</menu>
</adminhtml>
但我无法弄清楚如何在示例中创建第二个链接 two/index/index ?我如何在控制器中添加第二页?第二个链接的路径是什么?
我尝试在 one/IndexController 中做类似的事情
public function twoAction ()
{ $this->loadLayout(); etc...}
,并认为这可能会生成像 /one/index/two 这样的 url,但我不知道我在做什么(显然)。感谢您的帮助,magento 真的让我很困惑。
I am able to get one page to load in Magento admin using this in the controller which for this example would be in app/code/local/me/one/IndexController.php
:
public function indexAction()
{
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('one/one.phtml'));
}
and I created my menu with this in the config.xml
<adminhtml>
<menu>
<catalog>
<children>
<one_menu translate="title" module="foo">
<title>TEST</title>
<children>
<list translate="title" module="foo">
<title>one</title>
<action>one/index/index</action>
</list>
<new translate="title" module="foo">
<title>two</title>
<action>two/index/index</action>
</new>
</children>
</one_menu>
</children>
</catalog>
</menu>
</adminhtml>
But I cant figure how to create the second link in my example two/index/index ? How would I add that second page in the controller? What would the path be for that second link?
I tried to do something like this in the one/IndexController
public function twoAction ()
{ $this->loadLayout(); etc...}
and thought this might gnenerate a url like /one/index/two but I dont know what I am doing (obviously). Thanks for any help magento really confuses me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有正确的答案,但你却不知道。在 XML 中,将第二个
更改为one/index/two
,这将生成正确的 URL。现在,您可以在同一控制器中创建额外的twoAction()
方法,它将接收对该 URL 的请求。了解控制器调度 了解更多。还可以尝试像 这个 这样的配置,这样您的网址也可以以“admin”开头。
You have the right answer and don't know it. In the XML change the second
<action>
toone/index/two
, this will generate the correct URL. Now you can create that extratwoAction()
method in the same controller and it will receive requests for that URL.Read about controller dispatches to learn more. Also try a config like this one so your URLs can start with "admin" too.