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寫法請點擊查看


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM