我正在使用管理面板开发 Laravel 5.0 Web 应用程序。 我正面临路线问题。我有如下所示的分组管理路由,
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => ['user.admin']], function () {
Route::get('login', [
'as' => 'admin.login',
'uses' => 'AuthController@getLogin'
]);
Route::get('logout', [
'as' => 'admin.login',
'uses' => 'AuthController@getLogout'
]);
Route::post('login', 'AuthController@postLogin');
});
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => ['user.admin','auth', 'admin.acl']], function () {
Route::get('dashboard', [
'as' => 'admin.dashboard',
'uses' => 'DashboardController@index',
'permission' => 'admin_dashboard'
]);
//Image Handler
Route::get('images/{size}/{name?}',[
'as' => 'admin.images',
'uses' => 'ImagesController@images'
]);
Route::resource('user', 'UsersController');
........
});
一切正常。我可以毫无问题地使用以下内容,
http://domain.com/admin/dashboard
http://domain.com/admin/login
但是我想要
http://domain.com/admin
显示登录页面或重定向到
http://domain.com/admin/login
所以我把我的第一个组改成了following,
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => ['user.admin']], function () {
Route::get('/', [
'uses' => 'AuthController@getLogin'
]);
Route::get('login', [
'as' => 'admin.login',
'uses' => 'AuthController@getLogin'
]);
Route::get('logout', [
'as' => 'admin.login',
'uses' => 'AuthController@getLogout'
]);
Route::post('login', 'AuthController@postLogin');
});
现在当我访问
http://domain.com/admin
我在 Chrome 中收到“此网页有重定向循环”。是否可以在 Route 组中?如果不是如何使用 .htaccess 做到这一点?
更新
下面是一个中间件user.admin的handle方法。除了更改身份验证的基础模型外,什么都不做。
public function handle($request, Closure $next)
{
\Config::set('auth.table', 'admins');
\Config::set('auth.model', 'App\DB\Admin\Admin');
\Config::set('session.cookie', 'admin_session');
\Config::set('session.path', '/admin/');
return $next($request);
}
更新
这太棒了,下面的作品
http://domain.com/index.php/admin
我没有触及下面的 laravel 5.0 提供的默认 .htaccess,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
我有将近 60-70 条路线,所有路线都可以在没有 index.php accept 的情况下工作,在上述情况下我需要 index.php。
最佳答案
问题是“user.admin”中间件始终在运行,即使在“/admin/login”上也是如此。因此,当您访问“/admin”时,您将被重定向到“/admin/login”,然后中间件再次将您重定向到“/admin/login”,这种情况会永远发生。这就是您收到“此网页有重定向循环”的原因。
为了使其正常工作,您必须将“admin/login”排除在使用“user.admin”中间件之外。
关于php - Laravel 5 路由组和组内的 Basic(/) GET 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30871258/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
我们目前正在为ROR3.2开发自定义cms引擎。在这个过程中,我们希望成为我们的rails应用程序中的一等公民的几个类类型起源,这意味着它们应该驻留在应用程序的app文件夹下,它是插件。目前我们有以下类型:数据源数据类型查看我在app文件夹下创建了多个目录来保存这些:应用/数据源应用/数据类型应用/View更多类型将随之而来,我有点担心应用程序文件夹被这么多目录污染。因此,我想将它们移动到一个子目录/模块中,该子目录/模块包含cms定义的所有类型。所有类都应位于MyCms命名空间内,目录布局应如下所示:应用程序/my_cms/data_source应用程序/my_cms/data_ty
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
Rails中有没有一种方法可以提取与路由关联的HTTP动词?例如,给定这样的路线:将“users”匹配到:“users#show”,通过:[:get,:post]我能实现这样的目标吗?users_path.respond_to?(:get)(显然#respond_to不是正确的方法)我最接近的是通过执行以下操作,但它似乎并不令人满意。Rails.application.routes.routes.named_routes["users"].constraints[:request_method]#=>/^GET$/对于上下文,我有一个设置cookie然后执行redirect_to:ba
路由有如下代码:resources:orders,only:[:create],defaults:{format:'json'}resources:users,only:[:create,:update],defaults:{format:'json'}resources:delivery_types,only:[:index],defaults:{format:'json'}resources:time_corrections,only:[:index],defaults:{format:'json'}是否可以使用1个字符串为所有资源设置默认格式,每行不带“默认值”散列?谢谢。
我试图在我的网站上实现使用Facebook登录功能,但在尝试从Facebook取回访问token时遇到障碍。这是我的代码:ifparams[:error_reason]=="user_denied"thenflash[:error]="TologinwithFacebook,youmustclick'Allow'toletthesiteaccessyourinformation"redirect_to:loginelsifparams[:code]thentoken_uri=URI.parse("https://graph.facebook.com/oauth/access_token
我正在尝试提取方括号内的内容。到目前为止,我一直在使用它,它有效,但我想知道我是否可以直接在正则表达式中使用某些东西,而不是使用这个删除功能。a="Thisissuchagreatday[coolawesome]"a[/\[.*?\]/].delete('[]')#=>"coolawesome" 最佳答案 差不多。a="Thisissuchagreatday[coolawesome]"a[/\[(.*?)\]/,1]#=>"coolawesome"a[/(?"coolawesome"第一个依赖于提取组而不是完全匹配;第二个利用前瞻和