The following is some content written for members to conduct Yii framework training.
1) Download Yii 1.1.12:
2) Extract to /var/www/html, and rename the directory to yii;
3) Check whether the computer environment meets the requirements of yii. If not, please install the missing software; if it shows that php pdo was unsuccessful, please check whether the php.ini configuration items are consistent with those in 1.9;
4) To facilitate viewing the example program in the Yii framework, you can add sqlite database support in the php configuration file and restart Apache to take effect:
extension=php_pdo_sqlite.dll
5) Open the programs and websites that come with Yii and study its structure and programs:
http://127.0.0.1/yii/demos/helloworld/
http://127.0.0.1/yii/demos/blog/
Wait
6) Use Yii tool to generate a template website:
Open the command line tool: Start -> Run, the command is as follows:
C:Usersbihhe>d:
D:>cd /var/www/html/yii/framework
D:varwwwhtmlyiiframework>/var/php53/php /var/www/html/yii/framework/yiic.php webapp /var/www/html/test1
Open the browser and enter http://127.0.0.1/test1/index.php to access the created website.
7) Create database table:
CREATE TABLE `test1`.`test1_userinfo` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`uname` VARCHAR(45) NOT NULL,
`upass` VARCHAR(45) NOT NULL,
`count` INTEGER UNSIGNED,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB;
8) Modify the database connection method of the template website and modify test1/protected/config/main.php as follows:
/*
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
*/
using using
'db'=>array(
'connectionString' => 'mysql:host=127.0.0.1;dbname=test1',
'emulatePrepare' => true,
'password' => 'password',
'tablePrefix'=>'test1_',
),
After configuration, we can use Yii::app()->db to call the database connection anywhere.
9) Use Gii tool to generate Model and CRUD (add, delete, check and modify):
Edit protected/config/main.php as follows:
return array(
...
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'pick up a password here',
),
),
);
Open the webpage: http://127.0.0.1/index.php?r=gii
Enter the password to enter, select to generate model, enter the table name: test1_userinfo, Model class name: TUserInfo;
Click Generate, the Model class will be generated at: test1protectedmodels
Choose to generate CRUD in the same way, the code is generated at:
test1protectedcontrollers
test1protectedviewstUserInfo
Study test1protectedcontrollers TUserInfoController.php and other generated web pages
Enter the URL to access the web page just generated: http://127.0.0.1/test1/index.php?r=tuserinfo
Add module: Open the web page: http://127.0.0.1/index.php?r=gii
Enter the password to enter, select generate module, enter the UserInfo module name, and click Generate; the web page is generated at:
test1protectedmodulesUserInfo
Edit main.php as follows:
'modules'=>array(
using
'gii'=>array(
'class' = & gt; 'System.gii.giimodule',
'password'=>'nokialab',
to
'ipfilters' = & GT; Array ('127.0.0.1', ':: 1'),
),
'UserInfo',
),
Enter the URL http://127.0.0.1/test1/index.php?r=UserInfo/default/index to access the newly generated module.
10) Import the project in Eclipse: Please ensure that the eclipse version is helios for php version
Create a .project file in the project root directory with the content:
webprojectname
Create a .buildpath file in the project root directory with the content:
www.2cto.com
Open eclipse, File à Import à Existing Project into Workspace à Next à Select root directory, select the project directory and continue.
11) If the Yii page including view and layout has Chinese characters, please change the page saving format to utf-8, otherwise the Chinese display will be garbled;
http://www.bkjia.com/PHPjc/477809.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/477809.html
TechArticle
The following is some content written for members to conduct Yii framework training. 1) Download Yii 1.1.12: 2) Unzip it to /var/www/html, and rename the directory to yii; 3) Check whether the computer environment meets the requirements of yii...