在 magento admin 中从一个控制器创建多个页面

发布于 2024-12-22 03:42:35 字数 1639 浏览 0 评论 0原文

我可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后知后觉 2024-12-29 03:42:35

你有正确的答案,但你却不知道。在 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> to one/index/two, this will generate the correct URL. Now you can create that extra twoAction() 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文