我刚刚开始学习Laravel框架,我在路由方面遇到了一些问题。
唯一有效的路由是连接到Laravel的开箱即用的默认主路由。
我在Windows上使用WAMP,它使用PHP5.4.3和Apache2.2.22,我还启用了mod_rewrite,并从application.php配置文件中删除了'index.php‘以保留一个空字符串。
我已经创建了一个名为User的新控制器
class User_Controller extends Base_Controller {
public $restful = true;
public function get_index()
{
return View::make('user.index');
}
}
我用一些基本的代码在应用程序/视图/用户/中创建了一个名为index.php的视图文件,并在routes.php中添加了以下内容:
Route::get('/', function () {
return View::make('home.index');
});
Route::get('user', function () {
return View::make('user.index');
});
在我的web浏览器中访问根目录(http://localhost/mysite/public
)时,第一个路由工作得很好,但当我尝试使用http://localhost/mysite/public/user
转到第二个路由时,我得到了一个404not fine错误。为什么会发生这种情况?
发布于 2012-08-03 23:38:42
您是否尝试将其添加到路径文件中,而不是添加到Route::get('user', "user@index")
@
之前的文本片段(本例中为user
)将把页面定向到用户控制器,@
之后的文本片段index
将把脚本定向到user
函数public function get_index()
。
我看到您正在使用$restful
,在这种情况下,您可以将您的Route
设置为Route::any('user', 'user@index')
。这将同时处理POST
和GET
,而不是将它们分别写出来。
发布于 2015-01-20 02:44:00
在我的Ubuntu LAMP安装中,我通过以下两个更改解决了这个问题。
www
AllowOverride All
然后重新启动Apache服务器:service apache2 restart
发布于 2013-01-24 06:33:39
使用WAMP单击wamp图标->apache->apache modules->滚动并选中rewrite_module Restart a LoadModule rewrite_module
注意,一旦您启用了"rewrite_module“,服务器应用程序就会自动重新启动。
https://stackoverflow.com/questions/11791375
复制相似问题