Phalcon: Official multi-module support models layer, mode database configuration (ii)
Using: \pahlcon\mvc\model\manager::registernamespacealias () method to get the model layer under multi-module
public/index.php
Use Phalcon\mvc\model\manager as modelsmanager;//aliases the model $di->set (' Modelsmanager ', function () { return New Modelsmanager (); });
The model layer, my namespace is:
namespace App\modules\backend\models;
Namespace App\modules\backend\models;use \phalcon\mvc\model;class Album extends Model { //id public $aid; Template ID public $atid; public $name; Movie ID public $mid; Article 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; }}
So how does the controller layer invoke the model data?
Method has one:
$cate = \app\modules\backend\models\album::findfirst (Array ( ' conditions ' = =: aid: ', ' bind ' = = Array (' aid ' = $aid)) ;
Method two (Multi-table query):
Register aliases
$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");
The file under the model is assigned to the alias: M, then the specific data table is called: M:album, M:user ...
Phalcon: Official multi-module support models layer, mode database configuration (ii)