PHP Yii开源框架入门学习(一)
以下是给成员进行Yii框架培训写的一些内容。
1) 下载Yii 1.1.12:
2) 解压到 /var/www/html, 并将目录重命名为yii;
3) 检查电脑环境是否符合yii要求,不符合请安装所缺软件;若显示php pdo未成功,则请检查php.ini配置项是否和1.9中一致;
4) 为方便查看Yii框架中的例子程序,可在php配置文件中将sqlite数据库支持加上,重启Apache生效:
extension=php_pdo_sqlite.dll
5) 打开Yii自带的程序和网站,研究它的结构和程序:
http://127.0.0.1/yii/demos/helloworld/
http://127.0.0.1/yii/demos/blog/
等等
6) 使用Yii工具生成一个模板网站:
打开命令行工具:开始—>运行, 命令如下:
C:\Users\bihhe>d:
D:\>cd /var/www/html/yii/framework
D:\var\www\html\yii\framework>/var/php53/php /var/www/html/yii/framework/yiic.php webapp /var/www/html/test1
打开浏览器输入http://127.0.0.1/test1/index.php 即可访问创建的网站。
7) 创建数据库表:
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) 修改模板网站的数据库连接方式,修改test1/protected/config/main.php 如下:
/*
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=127.0.0.1;dbname=test1',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'tablePrefix'=>'test1_',
),
配好之后我们就可以在任何地方使用 Yii::app()->db调用该数据库连接了。
9) 使用Gii工具生成Model和CRUD(增删查改):
编辑protected/config/main.php 如下:
return array(
......
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'pick up a password here',
),
),
);
打开网页:http://127.0.0.1/index.php?r=gii
输入密码进入,选择生成model,输入表名:test1_userinfo, Model类名:TUserInfo;
点击生成,Model类将生成在:test1\protected\models
同样的方式选择生成CRUD,代码生成在:
test1\protected\controllers
test1\protected\views\tUserInfo
研究test1\protected\controllers\ TUserInfoController.php及其它生成的网页
输入网址即可访问刚才生成的网页: http://127.0.0.1/test1/index.php?r=tuserinfo
添加模块:打开网页:http://127.0.0.1/index.php?r=gii
输入密码进入,选择生成module,输入UserInfo模块名,点击生成;网页生成在:
test1\protected\modules\UserInfo
编辑main.php如下:
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'nokialab',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
'UserInfo',
),
输入网址http://127.0.0.1/test1/index.php?r=UserInfo/default/index 即可访问新生成的模块。
10) 在Eclipse中导入项目: 请确保eclipse版本为helios for php版本
在项目根目录下创建 .project文件,内容为:
在项目根目录下创建 .buildpath 文件,内容为:
打开eclipse,File à Import à Existing Project into Workspace à Next à Select root directory, 选择项目目录,继续即可。
11) Yii页面包括view、layout若有中文,请把页面保存格式改为utf-8,否则中文显示将成乱码;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools
