1、安装
(1)php环境安装请移步:
windows下php环境安装
linux下php环境配置
2、配置
Niginx 下配置 Phalcon
使用 Host 配置(Configuration by Host):
server{
listen 80;
server_name xxx.net;
charset utf-8;
set $root_path '/Library/xxx/xxx/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
# try_files $uri =404;
fastcgi_index /index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
access_log log/operator.log;
3、配置文件与入口文件
方式一、直接在index文件中配置
// 初始化自动加载器
$loader = new Loader();
$loader->registerDirs(
array(
'../app/controllers/',
'../app/models/'
)
)->register();
// 创建DI(依赖注入器),初始化注册组件
$di = new FactoryDefault();
// 数据库配置
$di['db'] = function() {
return new DbAdapter(array(
'host' => 'localhost',
'username' => 'root',
'password' => '123456',
'dbname' => 'test'
'charset' => 'utf8'
));
};
// 设置视图文件目录
$di['view'] = function() {
$view = new View();
$view->setViewsDir(APP_PATH.'/app/views/');
$view->setLayoutsDir('/layouts/');
$view->setTemplateBefore('before');
$view->setLayout('main');
$view->setTemplateAfter('after');
$view->setMainView('index');
$view->setPartialsDir('/partials/');
$view->start();
return $view;
};
// 注册一个基URI,这样所有使用Phalcon生成的URI里就会包含我们定义的phalcon。
// 这在以后我们使用\Phalcon\Tag生成URI时是非常重要的。
$di['url'] = function() {
$url = new Url();
$url->setBaseUri('/phalcon/');
return $url;
};
// Setup the tag helpers
$di['tag'] = function