PHP code example of houdunwang / route

1. Go to this page and download the library: Download houdunwang/route library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

houdunwang / route example snippets


Route::get('/',function(){
	return '后盾网 欢迎您';
});

Route::get('show', function(){
    return 'Hello HDPHP';
});

Route::post('user/add', function(){
    p($_POST);
});

Route::put('user/add', function(){
    p($_POST);
});

Route::DELETE('user/del',function(){
	p($_POST);
});

Route::any('user',function(){
	return '你好 后盾网';
});

Route::get('user/{id}', function($id){
    return 'User '.$id;
});

Route::get('user/{name?}', function($name = '后盾网'){
    return $name;
});

Route::get('user/{id}_{name}', function(){
    return Route::input();
});

Route::get('user/{id}', function($id){
    return $id;
})->where('id', '[0-9]+');

Route::get('user/{id}/{name}', function($id, $name){
    echo $id,$name;
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);

Route::get( 'user/{id}/{name}', function ($id, $f = '后盾人', \system\model\News $a, $name ) {
	echo $id, $name;
	dd( $f );
	dd( $a );
} )

namespace app\home\controller; 
class Entry{
	public function show($id,$cid){
		echo "访问是 $id,$cid";
	}
}


namespace app\home\controller;
class Entry{
	public function getIndex(){
		echo 'index';
	}
	public function getAdd(){
		echo 'add';
	}	
	public function postEdit(){
		echo 'edit';
	}
    public function putUpdate(){
		echo 'update';
	}
    public function deleteRemove(){
		echo 'delete';
	}
}

Route::group(['prefix' => 'admin'], function(){
    Route::get('add', function()
    {
        echo 'add';
    });
    
    Route::get('save', function()
    {
        echo 'save';
    });
});

namespace app\home\controller;
class Photo{
    //GET /photo 索引
    public function index(){
        echo 'index';
    }

    //GET /photo/create 创建界面
    public function create(){
        echo 'create';
    }

    //POST /photo 保存新增数据
    public function store(){
        echo 'store';
    }

    //GET /photo/{photo} 显示文章
    public function show($id){
        echo 'show';
    }

    //GET /photo/{photo}/edit 更新界面
    public function edit($id){
        echo 'edit';
    }

    //PUT /photo/{photo} 更新数据
    public function update($id){
        echo 'update';
    }

    //DELETE /photo/{photo} 删除
    public function destroy($id){
        echo 'destroy';
    }
}