yii目录部署

yiic:
下载最新yii源码 ,剪切出文件中的framework
cmd->进入配置站点下的framework目录下
yiic wepapp ../项目名称  回车-> 选择yes
项目创建完毕

目录部署:

设置首页和后台的入口文件,将前台和后台的模板 control model 分离,使用layout布局设置公共部分,前台设置主题目录, modules

设置首页和后台入口文件:
前台即为index.php  访问地址 www.myweb.com/项目名称 或者  www.myweb.com/项目名称/index.php?r=site/index
在protected下创建admin文件夹 必须包含 config/main.php   controllers/siteController.php   runtime   views
复制index.php重命名 admin.php
修改admin.php中的Yii::createWebApplication指向的main.php为你创建的admin/config/main.php 路径
修改main.php代码,这是我的代码,根据情况设置
<?php
$backend = dirname(dirname(__FILE__));
$frontend = dirname($backend);
Yii::setPathOfAlias('backend',$backend);
$frontendArray = require_once($frontend.'/config/main.php');
$backendArray=array(
 'name'=>'网站后台管理系统',
 'basePath'=>$frontend,
    'viewPath'=>$backend.'/views',
 'controllerPath'=>$backend.'/controllers',
    'runtimePath'=>$backend.'/runtime',
'defaultController'=>'site',   //设置默认控制器
 'import'=>array(
  'application.models.*',
  'application.components.*',
     'backend.models.*',
  'backend.components.*',
 ),
 //'params'=>CMap::mergeArray(require($frontend.'/config/params.php'),require($backend.'/config/params.php')),
 'theme' => '',
);
if(isset($frontendArray['components']['user'])){
 unset($frontendArray['components']['user']);
 return CMap::mergeArray($frontendArray,$backendArray);
}
这样后台与前台就分离了,访问后台地址 
www.myweb.com/项目名称/admin.php 或者  www.myweb.com/项目名称/admin.php?r=site/index

设置主题:前台页面需要做主题风格,供管理员选择喜欢的主题,主题设置 在前台config/main.php里加上 'theme' => '你的主题名称'
但是这样后台admin也会调用了此主题,可将admin/config/main.php中设置 theme为空  'theme' => '';这样前台页面会自动寻找theme/mytheme/views/下的模板  views文件夹必须创建,否则主题调用不到,如果在 
theme/mytheme/views/下的模板找不到该模板页面会自动去 protected/views/去寻找

使用layout设置公共部分 如:header footer,默认是调用 protected/views/layout/main.php,也可以自己定义,当我们的前台页面和会员中心的头部不一样的时候,就要进行设置的,在controller开头设置
public $layout='//layouts/main-2'; ”//“的意思是定位到views目录下寻找 main-2.php文件

css放在 根目录下下的css中新建一个js文件夹

modules 
你的项目可以分成n多的Module,然后每一个Module有自己的controllers和models。这样的组织结构,无论是开发,管理都方便简洁多了
在 config/main.php中添加modules元素
'fronts' => array(
   'class' => 'application.modules.fronts.FrontsModule',
  ),
在protected下新建 modules文件夹,新建一个刚才添加到modules元素名称相同的文件夹 这里是 fronts
在fronts文件夹下面 新建 FrontsModule.php controllers文件 viewsonic文件 
 FrontsModule.php 代码
class FrontsModule extends CWebModule
{
 public function init()
 {
  // this method is called when the module is being created
  // you may place code here to customize the module or the application
  // import the module-level models and components
  $this->setImport(array(
   'fronts.models.*',
   'fronts.components.*',
  ));
 }
 public function beforeControllerAction($controller, $action)
 {
  if(parent::beforeControllerAction($controller, $action))
  {
   // this method is called before any module controller action is performed
   // you may place customized code here
   return true;
  }
  else
   return false;
 }
}
yii自动寻找你新建的modules文件夹下的DefaultController.php 所以要有这个文件
输入网址  http://n你的域名/你的项目文件/index.php?r=fronts
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值