Comments (2)
挖掘到一个功能,发现路由可以介样写:
return array(
'/' => array(
'action' => 'Quotation\Action\Index',
'params' => array('routeName' => 'index')
),
'/s' => array(
'action' => 'Quotation\Action\Search',
'params' => array('routeName' => 'search')
),
'/brands' => array(
'action' => 'Quotation\Action\Brands',
'params' => array('routeName' => 'brands')
)
);
然后,利用 params 这个参数,就可以根据 routeName 获取对应的 url:
/**
* toUrl
* @return mixed
*/
public static function toUrl()
{
if (!self::$format) {
$routes = self::get('routes', ''); // 先取得路由配置,这个是我自己写的方法。
foreach ($routes as $k => $v) {
self::$format[$v['params']['routeName']] = asset(preg_replace('/:([_a-z]+)/i', '%s', $k));//asset 也是我自己的方法,用来组建 url
}
}
$args = func_get_args();
if (count($args) > 0) {
$name = $args[0];
$args = array_slice($args, 1);
return vsprintf(self::$format[$name], $args);
}
return self::$format;
}
from framework.
当然了,除此之外,你的action里相应也可以利用 params参数。
在你指定了 params 后,比如 'params' => array('routeName' => 'index')
,
action 里也会自动搜索是否存在 setRourteName
这个方法,如果存在,将自动执行。
执行顺序如下:init()
,你定义的 setRourteName
方法,最后是execute()
。
最后,还有一个好玩,除了定义'params'
外,还有一个参数可选,那就是拦截器,interceptors
,慢慢折腾吧...
from framework.
Related Issues (11)
- 关于缓存模块 HOT 5
- 注入的对象只能在 action 里 execute 方法里使用? HOT 16
- render json 是空的 HOT 3
- bad class name "Simple" HOT 1
- 没有文档
- Request::getArgs() can't get data from STDIN HOT 1
- Suggestion of support of setting http-only cookies.
- 希望统一目录后的斜杠问题 HOT 1
- 错误的路径如何引导进 action ? HOT 8
- 塞入 Data 对象的是空数组时报警告 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from framework.