Zend Framework:控制器目录中的子目录
我正在为我的网站使用 Zend Framework,并且刚刚创建了一个特殊的模块“api”来创建……嗯,一个 API。
现在,我的模块中有很多控制器,我想在此控制器目录中创建子目录以“整理”它。我的新结构将是这样的:
- controllers/
- controllers/contents/[controllers]
- controllers/users/[controllers]
- controllers/misc/[controllers]
但是,我发现自己完全无法找到使用 Zend_Controller_Router_Route 可以映射到这些控制器的哪种 url 和重定向。是否可以以某种方式做到这一点,或者我应该回到正常结构并将所有控制器放在同一个目录中?
我尝试使用 smack0007 建议的分隔符 _ ,并且考虑到 Zend Framework 通常如何引用子目录,这似乎是合乎逻辑的,但我收到了错误。
编辑:删除了长错误文本,因为它与问题无关,因为这只是一个问题,因为我没有使用正确的大小写,相信我必须将大写字母放在目录的第一个字母中。现在一切正常。
I'm using the Zend Framework for my website, and just created a special module "api" to create... Well, an API.
Now, I have a lot of controllers in my module and I'd like to create subdirectories in this controllers directory in order to "tidy" it. My new structure would be something like this :
- controllers/
- controllers/contents/[controllers]
- controllers/users/[controllers]
- controllers/misc/[controllers]
However, I find myself totally unable to find what kind of urls and redirections using Zend_Controller_Router_Route could map to these controllers. Is it possible to do this somehow or should I just go back to the normal structure and put all my controllers in the same directory ?
I tried using the separators _ as suggested by smack0007 and as it seemed logical given how Zend Framework usually refers to subdirectories, but I got an error.
Edit : Removed the long error text as it was not related to the question since it was only a problem because I didn't use the propre case, believing I had to put an uppercase to the first letter of the directory. All works well now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 1.5 版本的项目中已经这样做了,但我不知道它是否还能工作。
您必须在控制器前添加“{FOLDER}_”前缀,然后在网址中使用全名。
因此,在您的情况下,您将有一个名为:的控制器
和一条路线:
I've done this in project back in the 1.5 version but I don't know if it will work anymore.
You have to prefix your controllers with "{FOLDER}_" and then use the full name in the url.
So in your case you would have a controller named:
and a route:
我试图在旧应用程序的 url 上实现多个级别,并避免使用大量 url 规则。
所以我考虑将控制器分组到子目录中并为其定义 url 规则。
对于结构
在模块的 Bootstrap.php 中我添加了:
DefaultController.php 是
所以这将转发到子目录中的控制器。
最后,添加路由:
现在,例如,通过请求 test/default/sub/other/index,您可以在 OtherController.php 中调用 indexAction
I was trying to accomplish multiple levels at the url for an old application and avoiding to use a lot of url roules.
So I thought about grouping controllers into subdirectories and defining a url roule for it.
For a structure
In the Bootstrap.php of the module I added:
DefaultController.php is
So this will forward to our controller in the sub directory.
Finally, added the route:
Now e.g. with a request test/default/sub/other/index, you can call the indexAction in OtherController.php