1)在module文件夹下建立一个新的模块文件夹User
2)在新建的User文件夹下建立3个文件夹,名字分别为config、src、view
3)建立一个Module.php文件,此文件用来加载当前模块。Module.php代码如下
1 <?php
2 namespace User;//命名空间设置为和模块名相同
3
4 class Module
5 {
6 public function getConfig()
7 {
8 return include __DIR__ . '/config/module.config.php';
9 }
10
11 public function getAutoloaderConfig()
12 {
13 return array(
14 'Zend\Loader\StandardAutoloader' => array(
15 'namespaces' => array(
16 __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
17 ),
18 ),
19 );
20 }
21
22 }
4)config文件夹下建立module.config.php模块配置文件,基本代码如下
1 <?php 2 return array( 3 'controllers' => array( 4 'invokables' => array( 5 'User\Controller\Index' => 'User\Controller\IndexController' 6 ), 7 ), 8 'router' => array( 9 'routes' => array( 10 'user' => array( 11 'type' => 'Segment', 12 'options' => array( 13 'route' => '/user', 14 'defaults' => array( 15 '__NAMESPACE__' => 'User\Controller', 16 'controller' => 'User\Controller\Index', 17 'action' => 'index' 18 ) 19 ), 20 'may_terminate' => true, 21 'child_routes' => array( 22 'index' => array( 23 'type' => 'Segment', 24 'options' => array( 25 'route' => '/index[/][:action[/]]', 26 'constraints' => array( 27 'action' => '[a-zA-Z][a-zA-Z0-9_-]*' 28 ), 29 'defaults' => array( 30 // 要执行的默认控制器的名字是 IndexController 31 'controller' => 'User\Controller\Index', 32 // 要执行的默认控制器的方法是 indexAction() 33 'action' => 'index' 34 ) 35 ) 36 ) 37 ) 38 ) 39 ) 40 ) 41 );
5)src文件夹下建立User\Controller文件夹
6)src\User\Controller文件夹下建立IndexController.php,基本代码如下
<?php
namespace User\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class IndexController extends AbstractActionController
{
public function indexAction(){
echo "222222222";
exit;
}
}
如有错误请指正
来源:https://www.cnblogs.com/foreversimon/p/12191835.html