yiic webapp ../shop(任意名称)
:
PS:这里需要注意的是要在环境变量里加入php的路径
一些常用的配置和控件
mysql配置
"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/
对应此规则需要有一条规则是
’ucenter/
那么在createUrl的时候如果传递的uid参数为1,则会自动转到admin子域名
Apache Rewrite 对urlManger的影响
yii的urlManger使用的SERVER中的REQUEST_URI信息来做分析,然后解析到相应的controller中去,如果在apache中对某一个url单纯的进行rewrite是不能达到想要的目的的
比如:
RewriteRule ^/$ /fenlei/2/1.html [L]
这样的一条rewrite规则,得到的效果还是显示的首页,本来想是展示成分类页的,原因就是在rewrite的时候并不能改变REQUEST_URI的值,解决方案就是配合[P]使用,需要安装mod_proxy,相当于重新发起一次内部请求
最终写成这样:RewriteRule ^/$ /fenlei/2/1.html [P,L]
http://m.bbyears.com/jiaocheng/51484.html
推荐访问:yiyi英语