2016 yyuc框架环境配置
基礎準備
不懂php開發環境搭建的可以去網上搜索下。相信學習這個框架的童鞋們也都不是菜鳥級的了。?我習慣開發中直接用實際要發布的域名來做測試,這樣將來發布后會省去一些不必要的麻煩。?假如你的程序將來要發布到域名http://blog.csdn.net/qq_29572055上,這里簡單介紹一下方法:
1、修改本機host?,把你要測試開發的網絡地址指向本地:
用文本編輯器打開:C:\Windows\System32\drivers\etc\host?文件
最后一行添加:
1?127.0.0.1?blog.liqingbo.cn
這樣從你本機的瀏覽器請求網址www.test.com?都會被解析到你的本機ip?:?127.0.0.1上。
2、打開apache的?Virtual?Hosts配置文件?建立添加虛擬網站文件映射。
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、根據上面的配置可以看出,需要把工程test的開發目錄拷貝到D:/php下
4、默認情況下把框架的參考系統源碼目錄也拷貝到D:/php下
開發工具
這里推薦eclipse的php開發工具(PDT),筆者是從java開始接觸程序開發的所以推薦eclipse?下載地址:http://eclipse.org/pdt/downloads/?一般下載all?in?one就好。
本人本地配的域名是框架網站的主域名:
15?127.0.0.1?www.yyuc.net
特別說明:
1、因為示例中配置的域名是www.yyuc.net,所以下文所提到?www.yyuc.net的地方你都需要自換成自己的域名。
2、為了讓你更了解YY框架的原理和構成,我們先介紹幾個簡單的示例再介紹開發管理中心的使用,雖然開發管理中心會幫助我們省去一些敲代碼的工作量,但是作為初學者,還是建議你一步一步的往下看。
Nginx的配置:
linux下我們更常用nginx來代替apache完成頁面請求轉發的工作,下面是在一個簡單的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字符。
通過閱讀和學習通用簡單路由,你會知道這個請求頁面的控制器文件是:
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類是對頁面的一個封裝類,里面有一系列的靜態參數和方法供控制器直接修改和調用。
page::$need_view?默認為?true,執行完這個php文件之后框架會繼續加載它對應的視圖文件來執行,Page::ignore_view()將其設為?false則執行完php文件后就不再尋找視圖文件了。
Response::write?方法是向客戶端進行文本輸出,執行后立即退出腳本。
方式2:
hello.php?文件不寫任何代碼,可以建立空文件:controller/demo/hello.php。
建立文件:view/default/demo/hello.html
hello.html內容為:
116?
hello?World
由此可見,如果沒有執行Page::ignore_view(),框架執行了hello.php文件之后,控制器會自動尋找視圖文件hello.html文件加載執行。
方式3:
修改配置文件conf.php將$auto_find_view改為true。
117?/**是否開啟無控制器時自動尋找對應視圖~默認:false*/
118?public?static?$auto_find_view?=?true;
無需創建控制器文件直接建立文件:view/default/demo/hello.html
內容為:
119?
hello?World
配置數據庫
配置數據庫連接
這只是一個標準示例,實際開發中并不一定一定按照示例的方式進行。?框架的主配置文件是/yyuc/conf.php,它是一個被封裝好的靜類文件,有關數據庫的配置如下:
120?/**數據庫地址~*/
121?public?static?$db_host?=?"localhost";
122?/**數據庫端口~*/
123?public?static?$db_port?=?"3306";
124?/**數據庫名~*/
125?public?static?$db_dbname?=?"test";
126?/**數據庫用戶名~*/
127?public?static?$db_username?=?"root";
128?/**數據庫密碼~*/
129?public?static?$db_password?=?"";
130?/**數據庫表前綴~*/
131?public?static?$db_tablePrefix?=?"qq_";
總結
以上是生活随笔為你收集整理的2016 yyuc框架环境配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果cms内核H5网页漫画小说系统
- 下一篇: 数据结构与算法必备的 50 个代码实现。