yiic webapp ../shop(任意名称)
:PS:这里需要注意的是要在环境变量里加入php的路径
一些常用的配置和控件
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=test',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'aaaa',
'charset' => 'utf8',
),
gii配置
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'1111',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('*','127.0.0.1','::1','192.168.65.117'), //加上*后就可以去掉ip过滤功能,发布后再删除
'generatorPaths'=>array(
'bootstrap.gii', // since 0.9.1
),
),
),
yii-debug-toolbar (安装的时候遇到诡异问题,ext里面的目录太长,或者带-号时,报错,重命名解决问题
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
//array(
// 'class'=>'CFileLogRoute',
// 'levels'=>'error, warning',
//),
array(
'class'=>'ext.yiidebug.YiiDebugToolbarRoute',
'ipFilters'=>array('*','127.0.0.1','192.168.1.215'),
),
// uncomment the following to show log messages on web pages
//array(
// 'class'=>'CWebLogRoute',
//),
),
),
如果要查看sql执行,需要将db中的
'enableProfiling'=>true,
'enableParamLogging'=>true,
在发布到线上时,需要将此选项关闭
ActiveRecord数据转换成selection
$tmpTag=Tag::model()->findAllByAttributes(array('parentid'=>0));
echo $form->dropDownListRow($model,'parentid',CMap::mergeArray(array(0=>'一级tag'),
CHtml::listData($tmpTag,'tagid','tagname')));
urlManger
array(
'articles'=>'article/list',
'article/
)
第一条规则的意思是将‘/path/to/index.php/articles'的请求解析到 '/path/to/index.php/article/list';在调用createUrl生成url的时候正好反过来。
第二条规则用到了urlRule中的正则匹配,其中有一个id参数,它的意思是将 '/path/to/index.php/article/13'请求解析到 '/path/to/index.php/article/read?id=13'。
如果在urlManger中添加 'showScriptName' => false, 则url中的index.php可以被隐藏
urlManger中还有一个变量 'matchValue' => true, // 此变量是指在createUrl时是否匹配rule中的正则
这个在根据某一个参数需要对url进行特殊处理的时候比较有用,比如将uid=1的用户,定位到admin.**.com的子域名,那么rule中可以加下面一条:
‘http://admin.*****.com/ucenter/<1>1>
’