yaf mysql_适合初学者对Yaf框架的学习(二)

前言

一、Yaf的目录结构

1 YafWeb2 index.php #入口文件

3 application #应用目录

4 Bootstrap.php5 controllers #控制器目录

6 Index.php #默认Index控制器

7 library #本地类库

8 modules #其他模块

9 models #model目录

10 plugins #插件目录

11 views #视图目录

12 index #和Index控制器文件相对应目录

13 index.phtml #具体的index模板文件,后缀可以自己在配置文件中设置

14 conf #配置文件目录

15 app.ini #具体的配置文件

16 public #公共资源目录

5e53c06549d710e76d35257ca6907dbf.png

二、创建nginx配置文件yafweb.conf

server {

listen9880;#监听的端口号,这个由你自己来定

server_name101.200.***.***;#这个是我主机的ip,隐藏了后两个

index index.html index.htm index.php;

root/alidata/www/YafWeb/;

location~ .*\.(php|php5)?$

{#fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;include fastcgi.conf;

}

location~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location~ .*\.(js|css)?$

{

expires 1h;

}#伪静态规则

location /{if (!-e $request_filename) {

rewrite^/(.*)/index.php?$1last;

}

}

access_log/alidata/log/nginx/access/yafweb.log;

}

然后执行以下任意一条命令 重启或者平滑重启nginx

/etc/init.d/nginx reload

#或者/etc/init.d/nginx restart

三、各文件的内容

1.入口文件index.php

ini_set('yaf.library', APP_PATH.'/library');//第二个参数用来区分开发环境、测试环境、生产环境配置 对应config中内容

//实例化Bootstrap, 依次调用Bootstrap中所有_init开头的方法

$app = new Yaf_Application( APP_CONFIG."/app.ini",'common');$app->bootstrap()->run();

2.配置文件app.ini

[common]

application.modules= Index,Api

;layout

application.directory =APP_PATH

application.bootstrap = APP_PATH "/Bootstrap.php"application.library = APP_PATH "/library"application.layoutpath = APP_PATH "/view/"application.cache_config = 0application.view.ext = "phtml";app

application.baseUri = '';not used

application.dispatcher.defaultModule =index

application.dispatcher.defaultController =index

application.dispatcher.defaultAction =index

;database config 数据库配置

database.config.charset = "utf8"database.config.host =localhost

database.config.name = "mysql"database.config.user = "myuser"database.config.pwd = "mypwd"database.config.port = "3306";开发环境

[develop:common]

;errors (see Bootstrap::initErrors)

application.showErrors = 1application.throwException = 1;生产环境

[product:common]

;errors (see Bootstrap::initErrors)

application.showErrors = 0application.throwException = 0

说明:new Yaf_Application( APP_CONFIG."/app.ini",'common'); yaf读取配置文件app.ini,这样就会创建了一个对象

object(Yaf_Application)#1 (7) {

["config":protected]=>

object(Yaf_Config_Ini)#2 (2) {

["_config":protected]=>

array(2) {

["application"]=>

array(8) {

["modules"]=>

string(9) "Index,Api"["directory"]=>

string(31) "/alidata/www/YafWeb/application"["bootstrap"]=>

string(45) "/alidata/www/YafWeb/application/Bootstrap.php"["library"]=>

string(39) "/alidata/www/YafWeb/application/library"["cache_config"]=>

string(1) "0"["view"]=>

array(1) {

["ext"]=>

string(5) "phtml"}

["baseUri"]=>

string(0) ""["dispatcher"]=>

array(3) {

["defaultModule"]=>

string(5) "index"["defaultController"]=>

string(5) "index"["defaultAction"]=>

string(5) "index"}

}

["database"]=>

array(1) {

["config"]=>

array(6) {

["charset"]=>

string(4) "utf8"["host"]=>

string(9) "localhost"["name"]=>

string(5) "mysql"["user"]=>

string(4) "root"["pwd"]=>

string(10) "aa60dc2991"["port"]=>

string(4) "3306"}

}

}

["_readonly":protected]=>bool(true)

}

["dispatcher":protected]=>

object(Yaf_Dispatcher)#4 (10) {

["_router":protected]=>

object(Yaf_Router)#5 (2) {

["_routes":protected]=>

array(1) {

["_default"]=>

object(Yaf_Route_Static)#6 (0) {

}

}

["_current":protected]=>

NULL}

["_view":protected]=>

NULL["_request":protected]=>

object(Yaf_Request_Http)#3 (11) {

["module"]=>

NULL["controller"]=>

NULL["action"]=>

NULL["method"]=>

string(3) "GET"["params":protected]=>

array(0) {

}

["language":protected]=>

NULL["_exception":protected]=>

NULL["_base_uri":protected]=>

string(0) ""["uri":protected]=>

string(1) "/"["dispatched":protected]=>bool(false)

["routed":protected]=>bool(false)

}

["_plugins":protected]=>

array(0) {

}

["_auto_render":protected]=>bool(true)

["_return_response":protected]=>bool(false)

["_instantly_flush":protected]=>bool(false)

["_default_module":protected]=>

string(5) "Index"["_default_controller":protected]=>

string(5) "Index"["_default_action":protected]=>

string(5) "index"}

["_modules":protected]=>

array(2) {

[0]=>

string(5) "Index"[1]=>

string(3) "Api"}

["_running":protected]=>bool(false)

["_environ":protected]=>

string(7) "product"["_err_no":protected]=>int(0)

["_err_msg":protected]=>

string(0) ""}

3.Bootstrap.php文件

}

4.Base.php文件

{

}

}?>

5.Index控制器文件

{$this->getView()->assign("content", "Hello World");

}

}?>

6.index.phtml文件

Hello World

四、访问地址 http://101.200.***.***:9890/,看到以下内容,说明就成功了

5b6e97359e4298c11619a9d52dd8aa44.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值