4d47/http-resource 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

4d47/http-resource

Composer 安装命令:

composer require 4d47/http-resource

包简介

http resource

README 文档

README

The PHP paradox: PHP is a web framework. Any attempt at using PHP will result in building a web framework.

Install

composer require 4d47/http-resource:3.*

Usage

namespace App;

# First you define a 'class' of URLs.
# That's a set of documents that share the same structure of data and operations.
# Instances of the class will represents a specific URL.

class Product extends \Http\Resource {

    # The `$path` static variable holds the URL pattern that this resource
    # match.  When matched, the instance will have properties assigned with
    # the pattern variables.  Parenthesis can be used for optional variables,
    # colon denote a variable and a star matches anything. eg: `/foo((/:bar)/*)`

    public static $path = '/products/:name';

    # Then you implement HTTP methods, GET, POST, PUT, etc
    # to update the instance resource representation.
    # Server errors (5xx), client errors (4xx) and redirects (3xx) are sent by throwing
    # [http exceptions](http://github.com/4d47/php-http-exceptions).

    public function get() {
        if ($this->name == 'bazam')
            throw new \Http\NotFound();
        $this->price = 12;
    }

    # Implement any other methods you like
    public function __toString() {
        return sprintf("%s, %d$$", ucfirst($this->name), $this->price);
    }
}

Default render use scripts located in the views directory and named after the class name. Eg. views/app/product.php. The instance properties are extract before being included. $this reference the resource itself, it can be used to assign properties or call helpers methods. link is used to reference back resource path.

<a href="<?= \App\Product::link($name) ?>">
    <?= $this ?>
</a>

If there is a file named layout.php in the views subpath, the first one will be used. The $content variable will hold the result of the first view and $this will also be available. Eg. using views/layout.php.

<html>
<title><?= $this->title ?></title>
<body><?= $content ?></body>
</html>

Finally you bootstrap everything in your index.php by handling the list of your resources.

\Http\Resource::handle(['App\Product']);

See 4d47/php-start for a basic layout of the code.

统计信息

  • 总下载量: 186
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固