标签:index.php public 注册 命名 sharp phalcon ext model manager
phalcon:官方多模块支models层,mode数据库配置(二)
利用:\pahlcon\mvc\model\Manager::registerNamespaceAlias()方法获取多模块下的model层
public/index.php
use Phalcon\Mvc\Model\Manager as ModelsManager; //对模型进行别名处理 $di->set(‘modelsManager‘, function() { return new ModelsManager(); });
model层,我的命名空间是:
namespace App\Modules\Backend\Models;
namespace App\Modules\Backend\Models; use \Phalcon\Mvc\Model; class Album extends Model { //id public $aid; //模板id public $atid; public $name; //影片id public $mid; //文章id public $nid; public $enable; public $create_time; public function beforeCreate() { if( is_null($this->create_time) ) $this->create_time = time(); if( is_null($this->enable) ) $this->enable = 0; } }
那么controller层怎么调用model数据呢。
方法有一:
$cate = \App\Modules\Backend\Models\Album::findFirst(array( ‘conditions‘=>"aid = :aid:", ‘bind‘=>array(‘aid‘=>$aid) ));
方法二(多表查询):
注册别名
$this->modelsManager->registerNamespaceAlias(‘m‘ , ‘App\Modules\Backend\Models‘); $currentPage = $this->getParam(‘page‘); $builder = $this->modelsManager->createBuilder() ->columns("aid,atid,name,mid,nid,create_time") ->from("m:Album") ->where("enable = 0") ->orderBy("aid ASC");
将model下的文件,都赋给别名:m,那么调用具体的数据表就是: m:Album, m:User。。。。。。
phalcon:官方多模块支models层,mode数据库配置(二)
标签:index.php public 注册 命名 sharp phalcon ext model manager
原文地址:http://www.cnblogs.com/achengmu/p/7575686.html