zoukankan      html  css  js  c++  java
  • recess----1.第一个APP-helloRecess

    选择recess的理由很简单,这个架构看起来很轻量级,很简单。至少是写起应用来感觉不需要考虑太多和架构相关的东西。没有按作者给的过程一步步来,折腾了好久。。。在这里记录一下。

    安装过程略,官网文档无压力思密达。

    这里主要是添加我们的第一个应用,你可以有两种方法来实现:自己coding;使用recess提供的new app方法。

    自己coding的话,你可以更清楚的看到它做了些什么;使用new app方法的话,好处自己看吧。使用new方法的好处。。。唔,产生了一个配置很全面的app?貌似对我没有太多诱惑。

    使用recess提供的new app方法就不讲了,自己在装完recess之后点进去慢慢试。这里提供自己写的第一个APP,Hello Recess。这个是仿照官网Hello World写的啦。

    首先,你需要把这个APP相关的目录都建好了。

    app/
        helloRecess/
            controllers/
            views/
          home/

    然后,必须要一个APP的定义文件,而且名称必须是HelloRecessApplication.class.php,放在helloRecess目录下

    <?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就好啦~

    注意,上面的app行添加的是helloWorld.HelloWorldApplication,这里意思是,从app目录开始找,在一个叫helloWorld的目录下,有一个类文件叫HelloWorldApplication.class.php。根据我们的情况,您看着改吧。

    这里作者有解释:

    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什么的都去掉了。

  • 相关阅读:
    The Quad
    将OrCAD Capture CIS的设计文件(.dsn)导入到PADS Logic VX.2.3
    OrCAD Capture CIS 16.6 将版本16.6的设计文件另存为版本16.2的设计文件
    Eclipse IDE 添加jar包到Java工程中
    PADS Logic VX.2.3 修改软件界面语言
    切换Allegro PCB Editor
    Allegro PCB Design GXL (legacy) 将brd文件另存为低版本文件
    Allegro PCB Design GXL (legacy) 设置自动保存brd文件
    Could not create an acl object: Role '16'
    windows 下apache开启FastCGI
  • 原文地址:https://www.cnblogs.com/pied/p/3531367.html
Copyright © 2011-2022 走看看