phalcon: 官方多模块
目录结构如下
public/index.php:
use Phalcon\Mvc\Router;
use Phalcon\Tag;
use Phalcon\Mvc\Url;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\DI\FactoryDefault;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; // Create a DI
$di = new FactoryDefault(); $di->set('router', function () { $router = new Router(); $router->setDefaultModule("frontend"); $router->setDefaults(array(
"namespace" => 'Multiple\Frontend\Controllers',
"controller" => "Index",
"action" => "index"
));
//frontend
$router->add("/:controller", array(
'module'=>'frontend',
'controller' => 1,
));
$router->add("/:controller/:action", array(
'module'=>'frontend',
'controller' => 1,
'action' => 2,
));
$router->add("/:controller/:action/:param", array(
'module'=>'frontend',
'controller' => 1,
'action' => 2,
'param' => 3,
));
//backend
$router->add("/admin/:controller", array(
'module'=>'backend',
'namespace'=>'Multiple\Backend\Controllers', // 一定要加上,要不然找不到后台
'controller' => 1,
));
$router->add("/admin/:controller/:action", array(
'module'=>'backend',
'namespace'=>同上,
'controller' => 1,
'action' => 2,
));
$router->add("/admin/:controller/:action/:param", array(
'module'=>'backend',
'namespace'=>同上,
'controller' => 1,
'action' => 2,
'param' => 3,
)); return $router;
}); try { $di['db'] = function(){
return new DbAdapter(array(
"host" => "localhost",
"username" => "root",
"password" => "",
"dbname" => "demo",
"charset" => "utf8"
));
}; // Setup a base URI so that all generated URIs include the "tutorial" folder
$di['url'] = function() {
$url = new Url();
$url->setBaseUri('/');
return $url;
}; // 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',
)
)
);
echo $application->handle()->getContent();
} catch (Exception $e) {
echo "Exception: ", $e->getMessage();
}
frontend/module.php(backend/module.php的配置跟它的雷同):
<?php
namespace Multiple\Frontend; use Phalcon\Loader,
Phalcon\Mvc\Dispatcher,
Phalcon\Mvc\View,
Phalcon\Mvc\ModuleDefinitionInterface; class Module implements ModuleDefinitionInterface { public function registerAutoloaders( \Phalcon\DiInterface $di = NULL)
{
$loader = new Loader();
$loader->registerNamespaces(array(
'Multiple\Frontend\Controllers' => __DIR__ . '/controllers/',
'Multiple\Models' => __DIR__ . '/../models/'
))->register();
$loader->registerDirs(
array(
'modelsDir' => '../app/models/',
)
)->register(); } public function registerServices( \Phalcon\DiInterface $di)
{
$di->set("dispatcher", function(){
$dispatcher = new Dispatcher();
$dispatcher->setDefaultController("Multiple\Frontend\Controllers");
return $dispatcher;
}); $di->set("view", function(){
$view = new View();
$view->setViewsDir("../app/frontend/views/");
$view->registerEngines(array(
'.phtml' => 'Phalcon\Mvc\View\Engine\Php'
));
return $view;
}); }
}
frontend/controllers/indexController.php:
namespace Multiple\Frontend\Controllers;
//use Multiple\Models\Level;
class IndexController extends \Phalcon\Mvc\Controller { public function indexAction()
{
$level = Level::findFirst("id = 10");
$this->view->pick('index/index');
} }
models/Level.php
//namespace Multiple\Models;
class Level extends \Phalcon\Mvc\Model
{ public $lid;
public $name;
public $description;
public $create_time; public function beforeCreate()
{
if( is_null($this->create_time) )
{
$this->create_time = time();
} }
}
那么多模块下,如何分页的,如果直接用->from(表名),报错找不到此类,此时要引用model类的全命名空间名称如下:
Multiple\Models\Level(表)。
namespace Multiple\Backend\Controllers;
use Phalcon\Paginator\Adapter\QueryBuilder;
class IndexController extends ControllerBase { public function initialize()
{
parent::initialize(); } public function indexAction() { $builder = $this->modelsManager->createBuilder()
->columns("id,username,name,email")
->from('Users')
->orderBy("id ASC")
->getQuery()
->execute(); $paginator = new QueryBuilder(array(
"builder"=>$builder,
"limit"=>10,
"page"=>1
)); $this->view->setTemplateBefore('base');
$this->view->pick('index/index');
} }
phalcon: 官方多模块的更多相关文章
- phalcon:官方多模块支models层,mode数据库配置
phalcon:官方多模块支models层,mode数据库配置 按: backend分后台, frondend 分前台 每个多模块下面都有一个 Module.php文件, 1. frondend/mo ...
- phalcon:官方多模块支models层,mode数据库配置(二)
phalcon:官方多模块支models层,mode数据库配置(二) 利用:\pahlcon\mvc\model\Manager::registerNamespaceAlias()方法获取多模块下的m ...
- phalcon:整合官方多模块功能,方便多表查询
phalcon:整合官方多模块功能,方便多表查询 项目分为: namespace Multiple\Backend; namespace Multiple\Frontend; 目录结构如下: publ ...
- 【嵌入式开发】树莓派+官方摄像头模块+VLC串流实时输出网络视频流
sudo apt-get update sudo apt-get install vlc sudo raspivid -o - -t 0 -w 640 -h 360 -fps 25|cvlc -vvv ...
- Phalcon的Mvc结构及启动流程(部分源码分析)
Phalcon本身有支持创建多种形式的Web应用项目以应对不同场景,包括迷你应用.单模块标准应用.以及较复杂的多模块应用 创建项目 Phalcon环境配置安装后,可以通过命令行生成一个标准的Phalc ...
- Phalcon Framework的MVC结构及启动流程分析
目前的项目中选择了Phalcon Framework作为未来一段时间的核心框架.技术选型的原因会单开一篇Blog另说,本次优先对Phalcon的MVC架构与启动流程进行分析说明,如有遗漏还望指出. P ...
- windows,phalcon工具的安装使用
一.使用工具之前,必须安装phalcon的扩展,也就是php_phalcon.dll动态链接库 phalcon官方地址:https://github.com/phalcon/cphalcon/rele ...
- Phalcon Framework的Mvc结构及启动流程(部分源码分析)
创建项目 Phalcon环境配置安装后,可以通过命令行生成一个标准的Phalcon多模块应用 phalcon project eva --type modules入口文件为public/index.p ...
- Python的时间模块小结(转自:不懂真人)
import datetimeprint time.time() #时间戳 print time.localtime(time.time()) #时间元组 print time.strftime('% ...
随机推荐
- Java总结反射
[案例1]通过一个对象获得完整的包名和类名 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package Reflect; /** * 通过一个对象获得完整的包名和类名 ...
- wpfのuri(让你完全明白wpf的图片加载方式以及URI写法)
绝对 pack WPF URI pack://application:,,,/是协议:“,,,”是“///”的变体 1.资源文件 — 本地程序集 Uri uri = new Uri("pac ...
- 【Java】常见的Set类型,HashSet、TreeSet、LinkedHashSet
HashSet,锋芒毕露,我们最常用到.其他两个,我们较少用到,今天,我们看看他们的区别. import java.util.HashSet; import java.util.Set; public ...
- java.lang.UnsatisfiedLinkError: Couldn't load vi_voslib from loader dalvik.system.PathClassLoader
加载手机视频查看的JAR包时 运行提示 java.lang.UnsatisfiedLinkError: Couldn't load vi_voslib from loader dalvik.syste ...
- windows下安装laravel简单步骤以及碰到的问题
1.下载并安装composerhttp://pkg.phpcomposer.com/ ========================================================= ...
- Atlassian如何实施DevOps
DevOps是推动开发和运维团队之间沟通和协作的手段.它不是一个工具或产品.相反,其成功的首要因素就是文化.目的是更快的创新和更好的客户体验. "2015年DevOps状态报告"调 ...
- Highlighting Text Item On Entry In Oracle Forms
Highlight a Text Item in Oracle Forms With Visual Attribute It is very necessary to highlight the cu ...
- Dede CMS 5.5 升级到 5.7 SP1
Dede CMS 5.5 的漏洞实在是太多了,三天两头被Hacker们挂马.话说挂这些破网址真的能带来丰厚的回报吗?做人要厚道啊. 闲话少说,我按照网上的升级到5.5升级到5.7不出错的方法,升级 ...
- JSONObject.fromObject
JSONObject.fromObjectjava.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRun ...
- SQL——存储过程实例 调用带参数的过程(成绩输出)
create or replace procedure test_score(input in number,output out char) is begin then begin output : ...