2016 yyuc框架环境配置
基礎(chǔ)準(zhǔn)備
不懂php開發(fā)環(huán)境搭建的可以去網(wǎng)上搜索下。相信學(xué)習(xí)這個(gè)框架的童鞋們也都不是菜鳥級(jí)的了。?我習(xí)慣開發(fā)中直接用實(shí)際要發(fā)布的域名來做測試,這樣將來發(fā)布后會(huì)省去一些不必要的麻煩。?假如你的程序?qū)硪l(fā)布到域名http://blog.csdn.net/qq_29572055上,這里簡單介紹一下方法:
1、修改本機(jī)host?,把你要測試開發(fā)的網(wǎng)絡(luò)地址指向本地:
用文本編輯器打開:C:\Windows\System32\drivers\etc\host?文件
最后一行添加:
1?127.0.0.1?blog.liqingbo.cn
這樣從你本機(jī)的瀏覽器請(qǐng)求網(wǎng)址www.test.com?都會(huì)被解析到你的本機(jī)ip?:?127.0.0.1上。
2、打開apache的?Virtual?Hosts配置文件?建立添加虛擬網(wǎng)站文件映射。
2?
3?ServerAdmin?mqqkobe@163.com
4?DocumentRoot?"D:/php/test/pub"
5?ServerName?blog.liqingbo.cn
6?ErrorLog?"logs/dummy-host.somenet.com-error.log"
7?CustomLog?"logs/dummy-host.somenet.com-access.log"?common
8?
9?Options?FollowSymLinks
10?AllowOverride?All
11?Order?allow,deny
12?Allow?from?all?
13?
14?
3、根據(jù)上面的配置可以看出,需要把工程test的開發(fā)目錄拷貝到D:/php下
4、默認(rèn)情況下把框架的參考系統(tǒng)源碼目錄也拷貝到D:/php下
開發(fā)工具
這里推薦eclipse的php開發(fā)工具(PDT),筆者是從java開始接觸程序開發(fā)的所以推薦eclipse?下載地址:http://eclipse.org/pdt/downloads/?一般下載all?in?one就好。
本人本地配的域名是框架網(wǎng)站的主域名:
15?127.0.0.1?www.yyuc.net
特別說明:
1、因?yàn)槭纠信渲玫挠蛎莣ww.yyuc.net,所以下文所提到?www.yyuc.net的地方你都需要自換成自己的域名。
2、為了讓你更了解YY框架的原理和構(gòu)成,我們先介紹幾個(gè)簡單的示例再介紹開發(fā)管理中心的使用,雖然開發(fā)管理中心會(huì)幫助我們省去一些敲代碼的工作量,但是作為初學(xué)者,還是建議你一步一步的往下看。
Nginx的配置:
linux下我們更常用nginx來代替apache完成頁面請(qǐng)求轉(zhuǎn)發(fā)的工作,下面是在一個(gè)簡單的nginx配置示例:
16?user?www?www;
17??
18?worker_processes?1;
19??
20?error_log?/home/wwwlogs/nginx_error.log?crit;
21??
22?pid?/usr/local/nginx/logs/nginx.pid;
23??
24?#Specifies?the?value?for?maximum?file?descriptors?that?can?be?opened?by?this?process.
25?worker_rlimit_nofile?51200;
26??
27?events
28?{
29?use?epoll;
30?worker_connections?51200;
31?}
32??
33?http
34?{
35?include?mime.types;
36?default_type?application/octet-stream;
37??
38?server_names_hash_bucket_size?128;
39?client_header_buffer_size?32k;
40?large_client_header_buffers?4?32k;
41?client_max_body_size?50m;
42??
43?sendfile?on;
44?tcp_nopush?on;
45??
46?keepalive_timeout?60;
47??
48?tcp_nodelay?on;
49??
50?fastcgi_connect_timeout?300;
51?fastcgi_send_timeout?300;
52?fastcgi_read_timeout?300;
53?fastcgi_buffer_size?64k;
54?fastcgi_buffers?4?64k;
55?fastcgi_busy_buffers_size?128k;
56?fastcgi_temp_file_write_size?256k;
57??
58?gzip?on;
59?gzip_min_length?1k;
60?gzip_buffers?4?16k;
61?gzip_http_version?1.0;
62?gzip_comp_level?2;
63?gzip_types?text/plain?application/x-javascript?text/css?application/xml;
64?gzip_vary?on;
65??
66?#limit_zone?crawler?$binary_remote_addr?10m;
67??
68?#log?format
69?log_format?access?'$remote_addr?-?$remote_user?[$time_local]?"$request"?'
70?'$status?$body_bytes_sent?"$http_referer"?'
71?'"$http_user_agent"?$http_x_forwarded_for';
72?server
73?{
74?listen?80;
75?server_name?www.yyuc.net;
76?index?index.html?index.htm?index.php;
77?root?/home/test/pub;
78??
79?location?/?{
80?if?(!-e?$request_filename)?{
81?rewrite?^/(.*)$?/index.php?last;
82?}
83?}
84??
85?location?~?.*\.(php|php5)?$
86?{
87?try_files?$uri?=404;
88?fastcgi_pass?unix:/tmp/php-cgi.sock;
89?fastcgi_index?index.php;
90?include?fcgi.conf;
91?}
92??
93?location?/status?{
94?stub_status?on;
95?access_log?off;
96?}
97??
98?location?~?.*\.(gif|jpg|jpeg|png|bmp|swf)$
99?{
100?expires?30d;
101?}
102??
103?location?~?.*\.(js|css)?$
104?{
105?expires?12h;
106?}
107??
108?access_log?/home/wwwlogs/access.log?access;
109?}
110?}
hello?world
功能需求:
輸入地址http://www.yyuc.net/demo/hello.html,頁面顯示hello?wolrd字符。
通過閱讀和學(xué)習(xí)通用簡單路由,你會(huì)知道這個(gè)請(qǐng)求頁面的控制器文件是:
111?controller/demo/hello.php。
在controller文件夾下建立demo目錄和hello.php文件。
方式1:
編輯hello.php?代碼如下:
112?<?php?
113?Page::ignore_view();
114?Response::write("hello?world");
115??>
其中page類是對(duì)頁面的一個(gè)封裝類,里面有一系列的靜態(tài)參數(shù)和方法供控制器直接修改和調(diào)用。
page::$need_view?默認(rèn)為?true,執(zhí)行完這個(gè)php文件之后框架會(huì)繼續(xù)加載它對(duì)應(yīng)的視圖文件來執(zhí)行,Page::ignore_view()將其設(shè)為?false則執(zhí)行完php文件后就不再尋找視圖文件了。
Response::write?方法是向客戶端進(jìn)行文本輸出,執(zhí)行后立即退出腳本。
方式2:
hello.php?文件不寫任何代碼,可以建立空文件:controller/demo/hello.php。
建立文件:view/default/demo/hello.html
hello.html內(nèi)容為:
116?
hello?World
由此可見,如果沒有執(zhí)行Page::ignore_view(),框架執(zhí)行了hello.php文件之后,控制器會(huì)自動(dòng)尋找視圖文件hello.html文件加載執(zhí)行。
方式3:
修改配置文件conf.php將$auto_find_view改為true。
117?/**是否開啟無控制器時(shí)自動(dòng)尋找對(duì)應(yīng)視圖~默認(rèn):false*/
118?public?static?$auto_find_view?=?true;
無需創(chuàng)建控制器文件直接建立文件:view/default/demo/hello.html
內(nèi)容為:
119?
hello?World
配置數(shù)據(jù)庫
配置數(shù)據(jù)庫連接
這只是一個(gè)標(biāo)準(zhǔn)示例,實(shí)際開發(fā)中并不一定一定按照示例的方式進(jìn)行。?框架的主配置文件是/yyuc/conf.php,它是一個(gè)被封裝好的靜類文件,有關(guān)數(shù)據(jù)庫的配置如下:
120?/**數(shù)據(jù)庫地址~*/
121?public?static?$db_host?=?"localhost";
122?/**數(shù)據(jù)庫端口~*/
123?public?static?$db_port?=?"3306";
124?/**數(shù)據(jù)庫名~*/
125?public?static?$db_dbname?=?"test";
126?/**數(shù)據(jù)庫用戶名~*/
127?public?static?$db_username?=?"root";
128?/**數(shù)據(jù)庫密碼~*/
129?public?static?$db_password?=?"";
130?/**數(shù)據(jù)庫表前綴~*/
131?public?static?$db_tablePrefix?=?"qq_";
總結(jié)
以上是生活随笔為你收集整理的2016 yyuc框架环境配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果cms内核H5网页漫画小说系统
- 下一篇: 数据结构与算法必备的 50 个代码实现。