使用 Zend 在视图中创建额外的文件夹?
使用默认结构:
application
- controllers
- - IndexController.php
- models
- views
- - scripts
- - - index
- - - - index.phtml
- - - - create.phtml
我的控制器文件夹中的 IndexController.php 看起来像:
class IndexController extends Zend_Controller_Action { ... }
如果我想在其中添加一个文件夹,如下所示:
application
- controllers
- - IndexController.php
- models
- views
- - scripts
- - - index
- - - - posts
- - - - - index.phtml
- - - - - create.phtml
- - - - index.phtml
- - - - create.phtml
在什么路径和什么文件名中为我的帖子 indexAction 和 createAction 创建控制器?另外,您扩展了哪个控制器以及如何命名它?
With the default structure:
application
- controllers
- - IndexController.php
- models
- views
- - scripts
- - - index
- - - - index.phtml
- - - - create.phtml
My IndexController.php in my controllers folder would look like:
class IndexController extends Zend_Controller_Action { ... }
If I wanted to add a folder inside like this:
application
- controllers
- - IndexController.php
- models
- views
- - scripts
- - - index
- - - - posts
- - - - - index.phtml
- - - - - create.phtml
- - - - index.phtml
- - - - create.phtml
At what path and what file name do I create the controller for my posts indexAction and createAction? Also, which controller do you extend and how do you name it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您创建新操作(即:
postsAction()
)时,您需要在控制器视图脚本目录中创建一个与操作名称匹配的文件(在本例中为postsAction()< /code> 存在于
indexController
中)所以你需要的是这样的:
如果你想要一个结构,以便你有
/posts/index
或/posts/create< /code> 那么你可能想要一个
postsController
,它将包含如下所示的内容:如果你希望
/index/posts-create
作为中的一个操作>indexController
您将需要这样的目录结构 - 注意:当您使用带有驼峰命名法的操作时 (postsCreateAction()
) zend 框架会将其转换为全部小写URL 和视图脚本都带有破折号。您可能还想包含一个默认的
ErrorController
- 它将来会很有帮助。When you create a new action (ie:
postsAction()
) you need to create a file that matches the name of your action in the controllers view scripts directory (in this casepostsAction()
exists inindexController
)So what you need is this:
If you want a structure so that you have
/posts/index
or/posts/create
then you likely want to have apostsController
which will contain something that looks like this:If you want
/index/posts-create
as an action in yourindexController
your will need a directory structure like this - note: When you use an action with camelCase (postsCreateAction()
) zend framework converts it to all lowercase with dashes for both the URL and the view scripts.You may also want to include a default
ErrorController
- it will be helpful in the future.如果您将操作定义为驼峰命名法:
index/show-users-from-space
/views/index/show-users-from-space.phtml
if you define your actions camelCase like:
index/show-users-from-space
/views/index/show-users-from-space.phtml