// 在生产环境中请删除此行defined('YII_DEBUG') or define('YII_DEBUG',true);// 包含Yii引导文件require_once('path/to/yii/framework/yii.php');// 创建一个应用实例并执行$configFile='path/to/config/file.php';Yii::createWebApplication($configFile)->run();
Yii::app()->request->baseUrl;
Yii::app()->theme->baseUrl
Yii::app()->clientScript->registerCoreScript('jquery'); $cs=Yii::app()->clientScript;$cs->registerCSSFile(Yii::app()->request->baseUrl.'/css/main.css');or<?php echo CHtml::cssFile(Yii::app()->baseUrl.'/css/main.css'); ?> $cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/highslide/highslide.js', CClientScript::POS_HEAD); /protected/config/main.php
'theme'=>'basic',//启用皮肤'language'=>'zh_cn',//使用中文'import'=>array( 'application.models.*', 'application.components.*', 'application.extensions.*',),'defaultController'=>'site',//日志Yii::log($message, $level, $category);Yii::trace($message, $category);//语言调用Yii::t('app', 'Path alias "{alias}" is redefined.', array('{alias}'=>$alias))Yii::t('Xyz.categoryName', 'message to be translated')//调用用其他语言文件
$route='post/read'
;$params=array('id'=>100)
;$this->createUrl($route,$params);//相对路径Yii::app()->hostInfo;CHtml::link('Text',Yii::app()->controller->createAbsoluteUrl('controller/action'))
//login & logoutYii::app()->request->redirect(Yii::app()->user->returnUrl);
public function rules(){ return array( array('email', 'required', 'message'=>'{attribute}不能为空'), array('email', 'email', 'skipOnError'=>true), array('email', 'unique', 'skipOnError'=>true), array('username', 'length', 'min'=>3, 'max'=>12), array('password, repassword', 'match'), array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')), array('level', 'in', 'range' => array(1, 2), 'message'=>'{attribute}只能在1和2里面'), array('id', 'numerical'), );}$model->getErrors(); //返回 所有 模型特性的错误信息$model->getError();//返回 第一个 错误信息 $this->redirect(array('site/index'));//layout界面$this->renderPartial('_form', array('form'=>$form));//局部界面
Yii::app()->homeUrl;
<div id="mainmenu"> <?php $this->widget('zii.widgets.CMenu',array( 'items'=>Yii::app()->meun, )); ?></div><!-- mainmenu -->
$this->menu=array( array('label'=>'List Job', 'url'=>array('index')), array('label'=>'Create Job', 'url'=>array('create')),);