2010-12-07 85 views
1

使用默认结构:使用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中创建控制器的路径和文件名是什么?另外,你扩展了哪个控制器,你怎么命名它?

+0

是'posts`的一个动作?或者是你的行为`postsIndexAction`和`postsCreateAction`? – 2010-12-07 21:01:03

+0

这是适用于“部分视图”的情况下 – tawfekov 2010-12-07 21:11:17

回答

1

当你c reate新的动作(即:postsAction()),你需要创建在控制器视图脚本目录(在这种情况下postsAction()存在indexController)符合你的行动的名称的文件

所以,你需要的是这样的:

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

如果你想有一个结构,让你有/posts/index/posts/create,那么你可能想有一个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 - 这将在未来有所帮助。

0

如果你定义自己的行为驼峰喜欢:

public function showUsersFromSpaceAction() 
{ 
} 
  • 您的网址是: 指数/节目 - 用户 - 从空间
  • 和视图脚本: /人次/index/show-users-from-space.phtml
相关问题