获取与控制器关联的所有视图 - Zend
如果我以错误的方式处理这个问题,请告诉我,我会接受它作为一个潜在的答案。
我有一个模块化的 Zend Framework MVC 应用程序,在其中一个模块中,该站点的行为与静态 HTML 站点非常相似:
Category1_Controller
Category1_Subpage_Action1
Category1_Subpage_Action2
Category1_Subpage_Action2
Category2_Controller
Category2_Subpage_Action1
Category2_Subpage_Action2
Category3_Controller
Category3_Subpage_Action1
Category3_Subpage_Action2
Category3_Subpage_Action2
等等。为了节省时间,我想创建一个获取当前控制器的函数,然后与控制器关联的所有操作,并根据这两个变量创建动态导航(全局样式的 ul/li 列表)。创建实际的导航不是问题,但是如何根据模块内的控制器获取所有操作?这可能吗?
If I'm going about this the wrong way, please let me know and I'll accept that as a potential answer.
I have a Zend Framework MVC app that is modular, and in one of the modules the site acts very similar to a static HTML site:
Category1_Controller
Category1_Subpage_Action1
Category1_Subpage_Action2
Category1_Subpage_Action2
Category2_Controller
Category2_Subpage_Action1
Category2_Subpage_Action2
Category3_Controller
Category3_Subpage_Action1
Category3_Subpage_Action2
Category3_Subpage_Action2
Etc.. To save time, I'd like to make a function that grabs the current controller, then all of the actions associated with the controller, and create a dynamic navigation based on those two variables (ul/li list to be styled globally). Creating the actual navigation is not a problem, but how do I get all of the actions based on a controller within a module? Is that even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 php 函数 get_class_methods 从控制器中检索所有方法,然后检查每个方法以查看是否它以“行动”结束。
或者,您可以使用 ReflectionClass,但在这里可能有点过分了。
You can use the php function get_class_methods to retrieve all the methods from a controller, then check each method to see if it ends with 'Action'.
Alternatively you could use ReflectionClass, but it's probably overkill here.