phalcon:官方多模块支models层,mode数据库配置

按: backend分后台, frondend 分前台

每个多模块下面都有一个 Module.php文件,

1. frondend/models下面的mode文件,不需要写namespace命名空间,值机继承:\Phalcon\Mvc\Model类

2.在Module.php文件中添加此此代码:

public function registerAutoloaders( \Phalcon\DiInterface $di = NULL)
{
$loader = new Loader();
$loader->registerNamespaces(array(
'Multiple\Frontend\Controllers' => __DIR__ . '/controllers/',
'Multiple\Models' => __DIR__ . '/../models/'
))->register();
$loader->registerDirs(
array(
//'modelsDir' => '../app/models/',
//此处代码
'modelsDir' => '../app/frontend/models/',
)
)->register(); }

  

然后: \frontend\controllers\IndexController.php里面的控制器可以直接使用多模块内的Models层:

namespace Multiple\Frontend\Controllers;
class IndexController extends ControllerBase
{ public function indexAction()
{
$user = array();
$user = $this->session->get("user");
$this->view->user = $user; //$level = \Level::findFirst("lid = 1");
$level = \Level::getList();
var_dump($level);
if($level)
{
echo "yes";
}else{
echo "not";
}
exit; $this->view->setTemplateBefore('base');
$this->view->pick('index/index');
} }

  

05-11 21:55