Phpyii Framework Study Notes 1: Getting started, what you need to know for the first time .. Create several tables ~ For a brief description, tbl_postblog table tbl_comment comment table. tbl_user table tbl_tag label table can directly run the following SQL statement. CREATEDATABASE *! 32312 create several tables ~ For a brief description, the tbl_post blog table tbl_comment comment table and the tbl_user table tbl_tag label table can directly run the following SQL statement.
Create database /*! 32312 if not exists */'yii '/*! 40100 default character set utf8 */;
USE 'yii ';
Drop table if exists 'tbl _ comment ';
Create table 'tbl _ comment '(
'Id' int (11) not null AUTO_INCREMENT,
'Content' text,
'Status' tinyint (1) DEFAULT '0 ',
'Create _ time' timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
'Author' int (10) default null,
'Email 'char (255) default null,
'Post _ id' int (11) default null,
Primary key ('id ')
) ENGINE = MyISAM default charset = utf8;
Drop table if exists 'tbl _ lookup ';
Create table 'tbl _ lookup '(
'Id' int (11) not null AUTO_INCREMENT,
'Name' char (20) default null,
'Code' char (20) default null,
'Type' int (11) default null,
'Position' int (11) default null,
Primary key ('id ')
) ENGINE = MyISAM default charset = utf8;
Drop table if exists 'tbl _ post ';
Create table 'tbl _ post '(
'Id' int (11) not null AUTO_INCREMENT,
'Title' char (20) default null,
'Content' text,
'Tags' char (255) default null,
'Status' tinyint (2) DEFAULT '0 ',
'Create _ time' timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
'Update _ time' datetime default null,
'Author _ id' int (11) default null,
Primary key ('id ')
) ENGINE = MyISAM AUTO_INCREMENT = 2 default charset = utf8;
/* Data for the table 'tbl _ post '*/
Insert into 'tbl _ post' ('id', 'title', 'content', 'tags', 'status', 'create _ time', 'update _ time ', 'author _ id') values (1, '20170901', '20160901', '20160301', 1, '2017-08-08 00:00:00 ', '2017-08-08 00:00:00 ', 2 );
/* Table structure for table 'tbl _ tag '*/
Drop table if exists 'tbl _ tag ';
Create table 'tbl _ tag '(
'Id' int (11) not null AUTO_INCREMENT,
'Name' char (20) default null,
'Frequency 'Int (11) DEFAULT '1 ',
Primary key ('id ')
) ENGINE = MyISAM default charset = utf8;
Drop table if exists 'tbl _ user ';
Create table 'tbl _ user '(
'Id' int (11) not null AUTO_INCREMENT,
'Username' char (20) default null,
'Password' char (32) default null,
'Email 'char (100) default null,
'Sex' int (11) DEFAULT '0 ',
'Profile 'text,
Primary key ('id ')
) ENGINE = MyISAM AUTO_INCREMENT = 3 default charset = utf8;
Insert into 'tbl _ user' ('id', 'username', 'password', 'e-mail ', 'sex', 'Profile') values (1, 'admin ', 'e10adc3949ba59abbe56e057f20f883e ', NULL, 0, NULL), (2, 'demo', 'e10adc3949ba59abbe56e057f20f883e', NULL, 0, NULL );
2. modify the yii configuration file. protected/config/main. php
// Approximately 50th rows.
// 'DB' => array (
// 'Connectionstring' => 'sqlite: '. dirname (_ FILE _).'/../data/testdrive. db ',
//),
// Uncomment the following to use a MySQL database
'DB' => array (
'Connectionstring' => 'MySQL: host = 192.168.1.33; dbname = yii ',
'Default' => true,
'Username' => 'root ',
'Password' => 'admin ',
'Charset' => 'utf8', 'prefix' => 'tbl'
'Tableprefix' => 'tbl _'
),
// Approximately 21st rows. open gii ~
'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', '2017. 168.1.7 '),
),
),
$ User = User: model ()-> findByAttributes (array ('username' => $ this-> username ));
If ($ user = null ){
$ This-> errorCode = self: ERROR_USERNAME_INVALID;
} Else if ($ user-> password! = Md5 (trim ($ this-> password ))){
$ This-> errorCode = self: ERROR_PASSWORD_INVALID;
} Else {
$ This-> setState ('id', $ user-> id );
$ This-> setState ('username', $ user-> username );
$ This-> errorCode = self: ERROR_NONE;
}
Return! $ This-> errorCode;
Bytes ~ For a brief description, tbl_post blog table tbl_comment comment table. tbl_user table tbl_tag tag table can directly run the following SQL statement. CREATE DATABASE /*! 32312...