您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP Yii开源框架入门学习(一)_PHP教程

2024/12/8 22:13:07发布10次查看
以下是给成员进行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文件,内容为:
webprojectname
org.eclipse.wst.validation.validationbuilder
org.eclipse.dltk.core.scriptbuilder
org.eclipse.php.core.phpnature
在项目根目录下创建 .buildpath 文件,内容为:
www.2cto.com
打开eclipse,file à import à existing project into workspace à next à select root directory, 选择项目目录,继续即可。
11)   yii页面包括view、layout若有中文,请把页面保存格式改为utf-8,否则中文显示将成乱码;
http://www.bkjia.com/phpjc/477809.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/477809.htmltecharticle以下是给成员进行yii框架培训写的一些内容。 1) 下载yii 1.1.12: 2) 解压到 /var/www/html, 并将目录重命名为yii; 3) 检查电脑环境是否符合yii要求...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product