zend框架中的一个模块中的多个控制器
hi i am new in zend framework2.2.0. i want to create one module with multiple controller i have download "Album" module from github and its working fine Now i want to add the more controller in it the below i have shown my folder structure for file in module
module/
Album/
config/
module.config.php
src/
Album/
Controller/
AlbumController.php
UserController.php
Form/
AlbumForm.php
UserForm.php
Model/
AlbumTable.php
Album.php
UserTable.php
User.php
view/
album/
album/
index.phtml
user/
index.phtml
i have also changed all the name space in file
namespace Album\Controller;
class UserController extends \Zend\Mvc\Controller\AbstractActionController
and some indexAction method witch returns a new \Zend\View\Model\ViewModel();
then you can create your viewfile in
Album/view/Album/user/index.phtml i did above changes. is there any chage needed in "Album/Module.php" file ? can you tell me through which link i can see users list ?
i and tired with this error help me to get out of it
你好我是zend framework2.2.0的新手。 我想用多个控制器创建一个模块我从github下载“Album”模块并且工作正常 现在我想在其中添加更多控制器 下面我已经在模块中显示了我的文件夹结构 p>
module /
Album /
config /
module.config.php
src /
Album /
Controller /
AlbumController.php
UserController.php \ n Form /
AlbumForm.php
UserForm.php
Model /
AlbumTable.php
Album.php
UserTable.php
User.php
view /
album /
album /
index.phtml
user /
index.phtml
code> pre>
我还更改了文件中的所有名称空间 p>
namespace Album \ Contro ller; p>
类UserController扩展\ Zend \ Mvc \ Controller \ AbstractActionController p>
和一些indexAction方法返回一个新的\ Zend \ View \ Model \ ViewModel(); p>
然后您可以在 p>
专辑/视图/专辑/用户/索引.phtml
i中创建您的视图文件。
“Album / Module.php”文件中是否需要任何chage?
你能告诉我通过哪个链接我可以看到用户列表? p>
我厌倦了这个错误帮助我 摆脱它 p>
p> \ n div>
You may need to add url rules for user in module.config.php in Album/config folder. Then you can access the url like
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
'user' => array(
'type' => 'segment',
'options' => array(
'route' => '/user[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\User',
'action' => 'index',
),
),
),
),
),
Also
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
'Album\Controller\User' => 'Album\Controller\UserController',
),
),