Phalcon: Official multi-module support models layer, mode database configuration (ii)

Source: Internet
Author: User
Tags aliases

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.