zoukankan      html  css  js  c++  java
  • phalcon:整合官方多模块功能,方便多表查询

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

    项目分为:

    namespace MultipleBackend;
    namespace MultipleFrontend;

    目录结构如下:

    public/index.php的大致写法:

    多模块功能:

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

      

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

    backend/Module.php

    namespace MultipleBackend;
     
    use PhalconLoader,
        PhalconMvcDispatcher,
        PhalconDiInterface,
        PhalconMvcView,
        PhalconMvcModuleDefinitionInterface;
     
    class Module implements ModuleDefinitionInterface {
     
        public function registerAutoloaders( DiInterface $di = NULL)
        {
            $loader = new Loader();
            $loader->registerNamespaces(array(
                'MultipleBackendControllers' => __DIR__ .'/controllers/'
            ))->register();
            $loader->registerDirs(
                array(
                    'modelsDir'      => '../app/models/', #注意这里,必须填写,否则models/下的文件不能共用。
                )
            )->register();
     
        }
     
        public function registerServices( PhalconDiInterface $di)
        {
            $di->set("dispatcher", function(){
                $dispatcher = new Dispatcher();
                $dispatcher->setDefaultController("MultipleBackendControllers");
                return $dispatcher;
            });
     
            $di->set("view", function(){
                $view = new View();
                $view->setViewsDir("../app/backend/views/");
                $view->registerEngines(array(
                    '.phtml' => 'PhalconMvcViewEnginePhp'
                ));
                return $view;
            });
     
        }
    }
    

      

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

    use PhalconMvcModel;
    class Album extends Model {
      ......
    
    }
    

    controllers/下面的model调用:

    namespace MultipleBackendControllers;
    use PhalconPaginatorAdapterQueryBuilder 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;
                }
            }
    
    }
    

      

      

  • 相关阅读:
    sqlserver 中的 substring函数(转)
    C#二个相减怎么获得天数,就是比如201225 与201231之间相差的天数
    C++文件添加到项目中
    VS2008动态链接库(DLL)的创建与导入
    美剧字幕绿箭侠第1季第7集
    C++中#define用法
    C++头文件的重复引用
    visual studio中解决方案是什么
    NewWords/300400
    指针
  • 原文地址:https://www.cnblogs.com/achengmu/p/6890920.html
Copyright © 2011-2022 走看看