Laravel路由 [英] Laravel routing
问题描述
我是laravel的新手,我在路由时遇到问题。
我想要做的是使用我的路由,
域/ {controller} / {action}
这样我可以去家的测试页
首页/测试
文档对我来说没有意义,所以如果任何人都能指向正确的方向,是伟大的。
基本上你可以从:
Route :: get('Domain / {controller} / {action?}',function($ controller,$ action ='index'){
$ class = $ controller.'Controller';
$ controller = new $ class()
return $ controller - > {
$ action
}();
}) - > where(array('controller'=>'[az] +','action'=>'[az] +'))
你可以使用Route :: any来改变Route :: get以捕获所有
其他简单测试的例子:)
Route :: any('{controller} / {action?}',function($ controller,$ action ='index')
{
$ class = $ controller。'Controller';
$ controller = new $ class();
return $ controller-> {$ action}();
});
I'm new to laravel and I'm having trouble with routing.
What I'm trying to do is use my routes like so
Domain/{controller}/{action }
So that I can go to the home's test page
Home/test
The documentation doesn't really make sense to me so if anyone could point me in the right direction that would be great. Currently I'm hardcoding my routes for every page.
Basically you could start with:
Route::get('Domain/{controller}/{action?}', function ($controller, $action = 'index') {
$class = $controller.'Controller';
$controller = new $class()
return $controller - > {
$action
}();
}) -> where(array('controller' = > '[a-z]+', 'action' = > '[a-z]+'))
And you can change Route::get with Route::any to catch it all
Other simple tested example (should be working:)
Route::any('{controller}/{action?}', function($controller, $action = 'index') {
$class = $controller . 'Controller';
$controller = new $class();
return $controller->{$action}();
});
这篇关于Laravel路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!