cooky/url-router 问题修复 & 功能扩展

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

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

cooky/url-router

Composer 安装命令:

composer require cooky/url-router

包简介

Simple PHP Router

README 文档

README

Simple Routing and View System for PHP Projects

Install

composer require cooky/url-router

For Nginx - default_nginx.conf

root your_project_dir

location ~ \.css {
    add_header  Content-Type    text/css;
}
location ~ \.js {
    add_header  Content-Type    application/x-javascript;
}
location ~ \.ico {
    add_header  Content-Type    application/x-icon;
}
location / {
    rewrite ^(.*)$ /index.php/$1 last;
}

For Apache - .htaccess

RewriteEngine On
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Configration

vendor/cooky/url-router/config/configs/

Router Usage

/* main index.php */
require_once 'vendor/autoload.php';

/* */
use Routy\Route;

/* basic get */
Route::get('/', function (){
    echo '<h2>home page</h2>';
});

/* controller */
Route::get('/home', 'Home@Index');

/* with parameter */
Route::get('user/profile/{id}', 'User@Profile');

Route::post('test/post/{id}', function ($id){
    echo $id;
});

Route::complete();

Templating

/* layout.php */
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <link rel="stylesheet" href="css/default.css">
    
    <!-- Custom Css -->
    @yield(css)

    <title>routy basic templating</title>
</head>
<body>
    <!-- NAV -->
    <nav>NAV</nav>

    <!-- Dynamic Content -->
    @yield(content)

    <!-- FOOTER -->
    <footer>FOOTER</footer>

    <script src="node_modules/vue/dist/vue.js"></script>
    <!-- Dynamic Script -->
    @yield(script)
</body>
</html>

/* home.php */
<?php include "layout.php"; ?>

@section(css)
    <link rel="stylesheet" href="css/home.css">
@stop

@section(content)
    <div class="container" id="app">
        {{message}}
    </div>

    <!-- pass data from controller -->
    <div><?php echo $test; ?></div>
@stop

@section(script)
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                message: 'Hello Vue!'
            }
        })
    </script>
@stop

Controller

<?php use View\Loader;

/* Home controller - every controller must be extends with Loader for view */
class Home extends Loader
{
    public function index(){
        $data['test'] = 'hello kitty';
        $this->view('main', $data);
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-09-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固