选择recess的理由很简单,这个架构看起来很轻量级,很简单。至少是写起应用来感受不须要考虑太多和架构相关的东西。没有按做者给的过程一步步来,折腾了很久。。。在这里记录一下。php
安装过程略,官网文档无压力思密达。css
这里主要是添加咱们的第一个应用,你能够有两种方法来实现:本身coding;使用recess提供的new app方法。html
本身coding的话,你能够更清楚的看到它作了些什么;使用new app方法的话,好处本身看吧。使用new方法的好处。。。唔,产生了一个配置很全面的app?貌似对我没有太多诱惑。架构
使用recess提供的new app方法就不讲了,本身在装完recess以后点进去慢慢试。这里提供本身写的第一个APP,Hello Recess。这个是仿照官网Hello World写的啦。app
首先,你须要把这个APP相关的目录都建好了。ide
app/ helloRecess/ controllers/ views/
home/
而后,必需要一个APP的定义文件,并且名称必须是HelloRecessApplication.class.php,放在helloRecess目录下:ui
<?php Library::import(‘recess.framework.Application’); class HelloRecessApplication extends Application { public function __construct() { $this->name = ‘Hello Recess’; $this->viewsDir = $_ENV[‘dir.apps’].‘helloRecess/views/’; $this->modelsPrefix = ‘helloRecess.models.’; $this->controllersPrefix = ‘helloRecess.controllers.’;
$this->routingPrefix = ‘helloRecess/’; } } ?>
这样一个没有controller,没有model,没有view的三无产品就出炉啦思密达~只须要安装到recess就好啦!安装方法嘛,编辑根目录下的recess-conf.php就好啦~this
注意,上面的app行添加的是helloWorld.HelloWorldApplication,这里意思是,从app目录开始找,在一个叫helloWorld的目录下,有一个类文件叫HelloWorldApplication.class.php。根据咱们的状况,您看着改吧。spa
这里做者有解释:code
The convention of single classes per file and directories being broken up with dots is taken from the land of Java. The Recess library provides an layer important to auto-loading and performance between framework code and PHP’s native include_once and require_once methods.
好吧,如今点击 http://localhost/helloRecess/ 。你看到了啥?
抛出错误了是吧?第一个高端大气上档次的错误。
Resource does not exist.
throw new RecessResponseException('Resource does not exist.', ResponseCodes::HTTP_NOT_FOUND, get_defined_vars());
这就对了,没有controller是万万不行的!而后,咱们在helloRecess/controllers目录下建咱们的第一个controller,HelloRecessHomeController.class.php:
<?php Library::import('recess.framework.controllers.Controller'); /** * !RespondsWith Layouts * !Prefix Views: home/, Routes: / */ class HelloRecessHomeController extends Controller { /** !Route GET */ function index() { $this->message = 'Hello Recess!'; } } ?>
注意注释:
1)!Prefix Views: /home/, Routes: /。这是针对这个类的。这里告诉Recess,咱们的HelloRecessHomeController使用的是views/home/下的view文件,整个类的route是APP的根路径helloRecess/
2)!Route GET:这是针对method的。这里是告诉Recess,这个是处理helloRecess这个目录的GET请求时用的。也就是framework的Route定义。每一个method对应上面views目录(/views/home/)下的一个html.php文件,好比这里的index方法对应的是/views/home/index.html.php
固然,没有model能够,可是不能没有view啊,而后咱们在helloRecess/views/home/目录下建立一个view,index.html.php:
<html>
<header>
<title>Great Works!</title>
</header><body> <p>Hello Friends,</p>
<p>Message from controller:<?php echo $message; ?></p> <p>Great Works! You build your first APP in Recess successfully!</p> <p><strong><a href="http://www.cnblogs.com/pied">Luo Zhenxing</a></strong> <br />(<a href="mailto:piedgogo@gmail.com">e-mail</a>)</p>
</body>
</html>
而后,你再点点 http://localhost/helloRecess/ 试试?丑就丑点吧,为了例程最简,我把css什么的都去掉了。