Yii is also an MVC framework, which is suitable for various website development. It is very flexible and has high performance. The following charts show the efficiency of Yii compared with other popular PHP frameworks. In this chart, RPS indicates "requests per second" and describes the number of requests that the framework executes per second. The larger the number, the higher the performance of the framework. We can see that in this comparison
Yii is better than other frameworks.
After decompression, you can see that the Yii Framework contains three folders and four files, four of which are version descriptions and update logs. What we need is the framework folder, which is the core of the Yii framework.
1. The premise is that there is a WAMP development environment, which is not mentioned here. Then, create a project folder under the website directory and copy the framework folder.
2. Run cmd, first go to the Directory of the framework folder, and then run
Yiic webapp ../shop (any name):
PS: The php path should be added to the environment variable.
Some common configurations and controls
Mysql configuration
'DB' => array (
'Connectionstring' => 'MySQL: host = localhost; dbname = test ',
'Default' => true,
'Username' => 'root ',
'Password' => 'AAA ',
'Charset' => 'utf8 ',
),
Gii configuration
'Modules' => array (
// Uncomment the following to enable the Gii tool
'Giii '=> array (
'Class' => 'system. gii. GiiModule ',
'Password' => '123 ',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'Ipfilters '=> array (' * ', '2017. 0.0.1 ',': 1', '192. 168.65.117 '), // add * to remove the ip address filtering function, and delete it after publishing.
'Generatorpaths '=> array (
'Bootstrap. Gii', // since 0.9.1
),
),
),
Yii-debug-toolbar (encountered a strange problem during installation. The Directory in ext is too long or contains a-number. An error is reported. Rename the tool to solve the problem.
'Log' => array (
'Class' => 'clogrouter ',
'Routes '=> array (
// Array (
// 'Class' => 'cfilelogroute ',
// 'Levels' => 'Error, warning ',
//),
Array (
'Class' => 'ext. yiidebug. YiiDebugToolbarRoute ',
'Ipfilters '=> array (' * ', '2017. 0.0.1', '2017. 168.1.215 '),
),
// Uncomment the following to show log messages on web pages
// Array (
// 'Class' => 'cweblogroute ',
//),
),
),
To view SQL execution
'Enablesprofiling' => true,
'Enablesparamlogging' => true,
Disable this option when publishing to production.
ActiveRecord data to selection
$ TmpTag = Tag: model ()-& gt; findAllByAttributes (array ('parentid' => 0 ));
Echo $ form-> dropDownListRow ($ model, 'parentid', CMap: mergeArray (array (0 => 'Level 1 tag '),
CHtml: listData ($ tmpTag, 'tagid', 'tagname ')));
UrlManger
Array (
'Articles' => 'Article/list ',
'Article/<id: d +>/* '=> 'Article/read ',
)
The first rule indicates '/path/to/index. php/articles requests are parsed to '/path/to/index. php/article/list'; this is exactly the opposite when you call createUrl to generate a url.
The second rule uses the regular expression matching in urlRule. There is an id parameter, which indicates '/path/to/index. php/article/13 'request parsed to '/path/to/index. php/article/read? Id = 13 '.
If 'showscriptname' => false is added to urlManger, index. php in the url can be hidden.
There is also a variable 'matchvalue' => true in urlManger, // This variable is used to determine whether to match the regular expression in the rule when createUrl is used.
This is useful when you need to perform special processing on the url based on a specific parameter. For example, you can locate the user with uid = 1 in admin. **. com subdomain name, you can add the following to rule:
'Http: // admin. **. com/ucenter/<uid: 1>/* '=> 'User/Center ',
A rule corresponding to this rule must be
'Ucenter/<uid: d +>/* '=> 'User/Center'
If the passed uid parameter is 1 during createUrl, it will be automatically transferred to the admin subdomain name
Influence of Apache Rewrite on urlManger
The urlManger of yii uses the REQUEST_URI information in the SERVER for analysis, and then resolves it to the corresponding controller. If you perform rewrite on a url in apache, you cannot achieve the desired purpose.
For example:
RewriteRule ^/$/fenlei/2/1.html [L]
The result of such a rewrite rule is that the homepage is displayed as a category page, because the value of REQUEST_URI cannot be changed during rewrite, the solution is to work with [P] and install mod_proxy, which is equivalent to re-initiating an internal request.
It is written as follows: RewriteRule ^/$/fenlei/2/1.html [P, L]