phalcon: 【非官方】多模块
配合router使用
例如:我的模块叫做: home
入口文件增加引入:
use PhalconMvcRouter;
在自动引入前面增加,自动引入命名空间:
/** * 注册命名空间 */ $loader->registerNamespaces(array( 'controllers' => '../app/controllers' ))->register(); $loader->registerDirs( array( '../app/controllers/', '../app/models/' ) )->register();
增加router规则:
//router $di['router'] = function() { $router = new Router(); $router->add("/home/?([a-zA-Z0-9_-]*)/?([a-zA-Z0-9_]*)/:params", array( "namespace" => 'controllershome', "controller" => 1, "action" => 2, "params" => 3, )); $router->add("/index/:params", array( "namespace" => 'controllershome', "controller" => 'index', "action" => 'index', "params" => 1, ) ); $router->setDefaults(array( "namespace" => 'controllershome', "controller" => "Index", "action" => "index" )); return $router; };
第二步:在你home的controller文件夹下,都要定义命名空间
如:IndexController
<?php namespace controllershome; use PhalconMvcController; class IndexController extends Controller { public function indexAction() { echo "gaga"; $this->view->pick('home/index'); } }
目录结构如下: