Creating extra folder in views with Zend?
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?
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.
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
精彩评论