Yii 1.1 常规框架部署和配置

<?php
//index.php
//入口文件配置操作

// change the following paths if necessary
$yii=dirname(__FILE__).'/framework/yii.php'; //加载yii框架
$config=dirname(__FILE__).'/protected/config/main.php'; //加载配置如数据库等设定

// remove the following line when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);//开启调试模式

require_once($yii);
Yii::createWebApplication($config)->run();
<?php
//main.php
//数据库配置等操作

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'测试站YII_1.1',
    'language' => 'zh_cn',

    // preloading 'log' component  日志preloading组件
    'preload'=>array('log'),

    // autoloading model and component classes  自动加载模型和组件类
    'import'=>array(
        'application.models.*',
        'application.components.*',
    ),

    //默认控制器设定    Action到对应控制里面设定方法   例如: public $defaultAction = 'index';
    'defaultController'=>'index',

    //自定义模块
    'modules'=>array(
        'admin',
    ),

    // application components  应用组件
    'components'=>array(

/*        'user'=>array(
            // enable cookie-based authentication 启用cookie的身份验证
            'allowAutoLogin'=>true,
        ),*/

        // uncomment the following to use a MySQL database  MySQL数据库设定
        'db'=>array(
            'connectionString' => 'mysql:host=127.0.0.1:3306;dbname=test',
            'emulatePrepare' => true,
            'username' => 'root',
            'password' => 'root',
            'charset' => 'utf8',
            'tablePrefix' => 'blog_',//个人感觉不好用,不用可删除(不像常规TP框架可简写!)
        ),

        'errorHandler'=>array(
            // use 'site/error' action to display errors  报错显示错误级别
            'errorAction'=>'site/error',
        ),
        //url管理
        'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false, // 隐藏index,
            'caseSensitive' => false, // 大小写不敏感
            'rules'=>array(
/*                'post/<id:d+>/<title:.*?>'=>'post/view',
                'posts/<tag:.*?>'=>'post/index',
                '<controller:w+>/<action:w+>'=>'<controller>/<action>',*/
            ),
        ),
        //日志设定
        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, warning',
                ),
                // uncomment the following to show log messages on web pages
                /*
                array(
                    'class'=>'CWebLogRoute',
                ),
                */
            ),
        ),
    ),

    // application-level parameters that can be accessed 配置参数设定
    // using Yii::app()->params['paramName']
    'params'=>require(dirname(__FILE__).'/params.php'),
);
<?php
//AdminModule.php
//后台模块配置操作

class AdminModule extends CWebModule
{
    // public $defaultController = 'index';  //设置默认控制器

    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(
            'admin.models.*',
            'admin.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;
    }
}

php YII 1.0常用CURD写法请点击查看

原文地址:https://www.cnblogs.com/cxx8181602/p/8915955.html