2010-12-07 37 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
相關問題