一 php 薛强,PHP框架Yii系列教程:入门实例

[这里也强烈推荐YII框架,这个年轻的框架由美国华人开发,名叫薛强 。Yii 是2009最佳PHP框架 。Yii 是一个基于组件、用于开发大型 Web 应用的高性能 PHP 框架 。它将
1准备Yii源码
首先新建目录作为Web应用的根目录,并添加到Nginx的配置文件中 。然后将Yii框架源码部署到下 , 目录结构如下:
/
|--
|-- ……
|-- .php
|-- yiic
|-- yii.php
`-- zii
2编写
2.1目录结构
程序目录结构如下:
app/
|-- index.php
`--
|--
| `-- .php
`-- views
`-- hello
`-- .php
2.2主要代码
index.php
===============================================================================
//thepaths if
$yii=().'/..//yii.php';
//thelines when inmode
('') or ('',true);
//how manyof call stackbe shown in each
('') or ('',3);
($yii);
Yii::()->run();
//.php
===============================================================================
class
()
$ = "hi,yii";
$this->('', array(''=>$));
}[1环境准备安装服务端:yum -y .安装PHP-扩展:yum -y -pecl-.查看PHP-扩展是否安装成功:php
/views/hello/.php
===============================================================================
echo $;
2.3开始访问
3源码解析
3.1资源映射规则
访问Url经过index.php处理,将请求转发到的方法中 , 然后通过.php生成最终HTML页面 。具体映射关系如下图所示:
注:如果和为默认值site和index的话,则可以通过直接访问 。请求会转发给的()方法 。
4自动生成代码工具
Yii提供了Yiic和Gii两个代码生成工具,可以生成内容更加丰富的实例,下面就来试用一下 。
首先切换到//data/,然后执行:
/ demo
将会在//data//demo中自动生成示例程序代码 。
现在在浏览器中访问/demo/index.php即可看到成功页面 。
5常见问题
访问index.php时,PHP打印警告日志:: date(): It is not safe to rely on the 's . You are ** to use the date.or () …
在php.ini中设置默认时区,或者修改/demo//views//main.php:
===============================================================================
【一php 薛强,PHP框架Yii系列教程:入门实例】……