码迷,mamicode.com
首页 > 其他好文 > 详细

phalcon:整合官方多模块功能,方便多表查询

时间:2017-05-22 19:25:50      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:classname   views   parent   写法   目录   derby   path   log   ble   

phalcon:整合官方多模块功能,方便多表查询

项目分为:

namespace Multiple\Backend;
namespace Multiple\Frontend;

目录结构如下:

技术分享

 

public/index.php的大致写法:

多模块功能:

// Handle the request
    $application = new Application($di);
    //加入模块分组配置
    $application->registerModules(
        array(
            ‘frontend‘ => array(
                ‘className‘ => ‘Multiple\Frontend\Module‘,
                ‘path‘      =>  ‘../app/frontend/Module.php‘,
            ),
            ‘backend‘  => array(
                ‘className‘ => ‘Multiple\Backend\Module‘,
                ‘path‘      => ‘../app/backend/Module.php‘,
            )
        )
    );

  

来看下多模块下Module.php的写法,

backend/Module.php

namespace Multiple\Backend;
 
use Phalcon\Loader,
    Phalcon\Mvc\Dispatcher,
    Phalcon\DiInterface,
    Phalcon\Mvc\View,
    Phalcon\Mvc\ModuleDefinitionInterface;
 
class Module implements ModuleDefinitionInterface {
 
    public function registerAutoloaders( DiInterface $di = NULL)
    {
        $loader = new Loader();
        $loader->registerNamespaces(array(
            ‘Multiple\Backend\Controllers‘ => __DIR__ .‘/controllers/‘
        ))->register();
        $loader->registerDirs(
            array(
                ‘modelsDir‘      => ‘../app/models/‘, #注意这里,必须填写,否则models/下的文件不能共用。
            )
        )->register();
 
    }
 
    public function registerServices( \Phalcon\DiInterface $di)
    {
        $di->set("dispatcher", function(){
            $dispatcher = new Dispatcher();
            $dispatcher->setDefaultController("Multiple\Backend\Controllers");
            return $dispatcher;
        });
 
        $di->set("view", function(){
            $view = new View();
            $view->setViewsDir("../app/backend/views/");
            $view->registerEngines(array(
                ‘.phtml‘ => ‘Phalcon\Mvc\View\Engine\Php‘
            ));
            return $view;
        });
 
    }
}

  

models/下的model文件,不需要命名空间,直接写:

use \Phalcon\Mvc\Model;
class Album extends Model {
  ......

}

 

controllers/下面的model调用:

namespace Multiple\Backend\Controllers;
use Phalcon\Paginator\Adapter\QueryBuilder as PaginatorQueryBuilder;
class AlbumController extends ControllerBase {

    public function initialize(){
        parent::initialize();
    }

    public function indexAction()
    {

        $currentPage = $this->getParam(‘page‘);
        $builder = $this->modelsManager->createBuilder()
            ->columns("aid,atid,name,mid,nid,create_time")
            ->from("Album")
            ->where("enable = 0")
            ->orderBy("aid ASC");

        $paginator = new PaginatorQueryBuilder(array(
            ‘builder‘ => $builder,
            ‘limit‘ => 10,
            ‘page‘ => $currentPage
        ));
        $category = ‘‘;
        if( $this->getAlbumCategory() )
        {
            foreach($this->getAlbumCategory() as $k=>$v)
            {
                $category[$v[‘atid‘]] = $v;
            }
        }

}

  

 

  

 

phalcon:整合官方多模块功能,方便多表查询

标签:classname   views   parent   写法   目录   derby   path   log   ble   

原文地址:http://www.cnblogs.com/achengmu/p/6890920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!