-
Notifications
You must be signed in to change notification settings - Fork 3
Route
Nolan Chou edited this page Dec 1, 2015
·
10 revisions
// use config
return array(
'routes' => array(
'/path/' => array(
'params' => '$param1/$param2',
'callback' => 'class::method',
),
),
);
or
use pt\framework\route as route;
route::add('/path/', 'callback', '$param1/$param2');
callback
can be a method/function or anonymous function.
path
is a rule of pathinfo. like '/User/info/' or '/Product/' or '/'.
params
will put value into $_GET.
example:
rule: '/Test/';
params: '$method/id/$id/$page';
pathinfo: '/Test/abc/id/1/2';
callback will get 4 args: abc, id, 1, 2.
$_GET is array('method'=>'abc', 'id'=>1, 'page'=>2);
route::init();
If you need a single entity framework, use route like :
// use config
return array(
'routes' => array(
'/' => array(
'params' => '',
'callback' => function()
{
$args = func_get_args();
$controller = $_GET['c'] = empty($args[0]) ? 'index' : $args[0];
$method = $_GET['m'] = empty($args[1]) ? 'index' : $args[1];
for($i = 2; $i < count($args); $i=$i+2)
{
$k = $args[$i];
$_GET[$k] = empty($args[$i+1]) ? '' : $args[$i+1];
}
call_user_func("{$controller}::{$method}");
},
),
),
);
Nginx server need set PATH_INFO for fastcgi
location ~ \.php
{
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($uri ~ "^(.+?\.php)(\/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
And check your rewrite option. Like:
rewrite ^/(.*)$ /index.php/$1;
- License Agreement
- Change Log
- Welcome
- Server Requirements
- Getting Started
- Datebase
- Template
- Debug
- Route
- Log
- Language
- Dynamic expansion of class
- Callback
- Hook
- File
- Image
- Page
- String
- Upload
- Action (hook)
- Filter (hook)