Skip to content

tonnychina/iphp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

223 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

项目文件组织(目录结构)

app/	classes/	config/	console/	controllers/	models/	views/ css/ fonts/ js/ deploy.sh server.sh index.php 

利用 tools/new_app.php 来创建新项目

在你想建立项目的目录底下, 执行:

php <somewhere>/tools/new_app.php 

这是执行效果:

$APP['NAME']: myfirstapp $APP['DOMAIN']: localhost $APP['PHP_FPM.PORT']: 9000 Generate app into: /Users/ideawu/Works/iphp/tmp/myfirstapp ... Done! 

项目部署

进入你的项目源码目录, 然后执行

sh deploy.sh dev sh server.sh restart 

Nginx 配置

在已配置了 PHP 的情况下, 你只需要简单添加下面的内容到你的 nginx.conf 里, 然后重启 nginx 即可.

location / {	try_files $uri $uri/ /index.php?$args; } 

这个配置表示以 / 开头的请求都尝试交给 /index.php 处理, 如果请求不对应某个文件(可能产生 404)的话.

如果想把你的项目放在 /my 目录下, 那么配置文件就是这样:

location /my/ {	try_files $uri $uri/ /my/index.php?$args; } 

不过, 基于安全等考虑, 你还需要配置更多的东西, 具体参考附带的 demo/app/config/nginx.conf 模板.

location / {	location ~ /(app|logs)/ {	deny all;	}	location ~ \.(sh|sql|conf|key|crt|csr) {	deny all;	}	location ~ \.(gif|png|jpg|ico|svg|css|js|ttf|woff|eot)$ {	}	try_files $uri $uri/ /index.php?$args; } 

注意: 如果你的 nginx.conf 没有配置 index index.php;, 请加上.

URL 路由

路由规则

Project URL Path => Controller + View 

路由规则用于将一个 URL 路径, 转变为某一个控制器类(Controoler)的某个实例方法(Action)的执行, 以及某一个视图文件的渲染(View). 这个 URL 路径是相对路径, 相对项目的首页, 如项目的首页是 /my/, 那么 /my/a/b/c 的 URL 路径便是 a/b/c.

例子

URL 路径

a/b/c 

控制器(Controller)查找顺序

a/b.php a/b/c.php a/b/c/index.php 

方法(Action)查找

index() 或者 c() 

视图(View)查找顺序

a/b/c.tpl.php a/b/c.tpl.php a/b/c/index.tpl.php 

模板(Layout)查找顺序

模板文件(Layout)用于定义网页的整体框架, 并在其中某个位置加入

<?php _view(); ?> 

表示将视图(View)的内容插入此处. 模板文件默认必须是 layout.tpl.php, iphp 首先在视图(View)文件所在的同目录查找该文件, 如果找不到则查找上一级, 直到 views 目录为止.

演示

Path Controller Aaction View Full URL
about about.php AboutController#index about.tpl.php http://localhost/iphp/about
about/us about.php AboutController#us about/us.tpl.php http://localhost/iphp/about/us
about/job about/job.php JobController#index about/job.tpl.php http://localhost/iphp/about/job
api/test api/test.php TestController#index None http://localhost/iphp/api/test

About

An everyone can understand PHP framework for web development

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

No contributors

Languages

  • PHP 96.2%
  • Shell 2.7%
  • CSS 1.1%