使用 Zend 在视图中创建额外的文件夹?

发布于 2024-10-06 15:52:11 字数 630 浏览 2 评论 0原文

使用默认结构:

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 技术交流群。

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

发布评论

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

评论(2

温柔女人霸气范 2024-10-13 15:52:11

当您创建新操作(即:postsAction())时,您需要在控制器视图脚本目录中创建一个与操作名称匹配的文件(在本例中为postsAction()< /code> 存在于 indexController 中)

所以你需要的是这样的:

application
- controllers
- - IndexController.php
- views
- - scripts
- - - index
- - - - posts.phtml
- - - - index.phtml
- - - - create.phtml

如果你想要一个结构,以便你有 /posts/index/posts/create< /code> 那么你可能想要一个 postsController ,它将包含如下所示的内容:

application
- controllers
- - IndexController.php
- - PostsController.php
- models
- views
- - scripts
- - - index
- - - - index.phtml
- - - - create.phtml
- - - posts
- - - - index.phtml
- - - - create.phtml

如果你希望 /index/posts-create 作为 中的一个操作>indexController 您将需要这样的目录结构 - 注意:当您使用带有驼峰命名法的操作时 (postsCreateAction()) zend 框架会将其转换为全部小写URL 和视图脚本都带有破折号。

application
- controllers
- - IndexController.php
- models
- views
- - scripts
- - - index
- - - - index.phtml
- - - - create.phtml
- - - - posts-create.phtml

您可能还想包含一个默认的 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 case postsAction() exists in indexController)

So what you need is this:

application
- controllers
- - IndexController.php
- views
- - scripts
- - - index
- - - - posts.phtml
- - - - index.phtml
- - - - create.phtml

If you want a structure so that you have /posts/index or /posts/create then you likely want to have a postsController which will contain something that looks like this:

application
- controllers
- - IndexController.php
- - PostsController.php
- models
- views
- - scripts
- - - index
- - - - index.phtml
- - - - create.phtml
- - - posts
- - - - index.phtml
- - - - create.phtml

If you want /index/posts-create as an action in your indexController 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.

application
- controllers
- - IndexController.php
- models
- views
- - scripts
- - - index
- - - - index.phtml
- - - - create.phtml
- - - - posts-create.phtml

You may also want to include a default ErrorController - it will be helpful in the future.

你的背包 2024-10-13 15:52:11

如果您将操作定义为驼峰命名法:

public function showUsersFromSpaceAction()
{
}
  • 您的网址将是:
    index/show-users-from-space
  • 和您的视图脚本:
    /views/index/show-users-from-space.phtml

if you define your actions camelCase like:

public function showUsersFromSpaceAction()
{
}
  • your url will be:
    index/show-users-from-space
  • and your view script:
    /views/index/show-users-from-space.phtml
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文