【问题标题】:Create a current class for my dynamic menu为我的动态菜单创建一个当前类
【发布时间】:2011-02-03 12:31:54
【问题描述】:

似乎创建一个当前类比我想象的要难:)

模块/菜单/动作/components.class.php

$this->元素 = 数组( "我的页面" => "内容/索引", "管理员" => "内容/索引", ); $this->current = ""; foreach($this->elements as $name => $link) { list($module, $action) = explode("/", $link); if ($this->getContext()->getModuleName() == $module && $this->getContext()->getActionName() == $action) { $this->current = $name; } }

模块/菜单/模板/_main.php

if ($current == $name){ echo link_to($name, $link, array("class" => "selected")); }别的 { 回声链接到($名称,$链接); }

如果您查看链接,它们会转到“内容/索引”(目前)。 最大的问题是,内容/索引重定向到 auth/login,所以当前模块和操作,即使 URL 显示内容/索引是 auth/login。

谢谢

【问题讨论】:

    标签: php symfony1


    【解决方案1】:

    只是一个想法:

    1. 重定向登录页面时设置return参数
    2. 解析这个参数而不是实际的url

    或者:

    1. 使用路由,而不是“模块-动作”对
    2. 转发而不是重定向到授权路由
    3. $currentRouteName = $this->getContext()->getRouting()->getCurrentRouteName()

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多