Php Laravel路由在MAMP上不起作用
我刚刚开始学习laravel,我正在使用MAMP。我在这个url上有一个表单:但是当我提交表单时,它会把我带到这个url:并且不会停留在我期望的地方 routes.php文件包含以下内容:Php Laravel路由在MAMP上不起作用,php,.htaccess,laravel,laravel-4,Php,.htaccess,Laravel,Laravel 4,我刚刚开始学习laravel,我正在使用MAMP。我在这个url上有一个表单:但是当我提交表单时,它会把我带到这个url:并且不会停留在我期望的地方 routes.php文件包含以下内容: Route::get('ducks', function() { return View::make('duck-form'); }); // route to process the ducks form Route::post('ducks', function() { // pro
Route::get('ducks', function()
{
return View::make('duck-form');
});
// route to process the ducks form
Route::post('ducks', function()
{
// process the form here
});
在.htaccess文件中,我有以下内容:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel-site/my-new-app/public/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
选项-多视图
重新启动发动机
RewriteBase/laravel站点/我的新应用程序/公共/
#重定向尾部斜杠。。。
重写规则^(.*)/$/$1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
我可能遗漏了一些非常明显的内容,但为什么我提交表单时,表单不在同一页面上?检查您的应用程序url是否在config/app.php中设置正确:
'url' => 'http://localhost:8888/laravel-site/my-new-app/public',
并确保您的表单按照正确的路线提交
Form::open(array('route' => 'ducks'))
只需使用命名路由。这应该会有帮助
Route::get('ducks', array('as' => 'showForm', function()
{
return View::make('duck-form');
}));
// route to process the ducks form
Route::post('ducks', function()
{
// the get route is named as showForm
return Redirect::route('showForm');
});
您尚未提供表单的HTML,但我猜您硬编码了如下内容,并希望Laravel能够使其正常工作:
<form method="post" action="/ducks">
这将为您提供正确的URL。记住不要在URL的开头使用/
,Laravel已经假设所有URL都是相对于应用程序根目录的(但不一定是web服务器文档根目录)
除此之外,您还应采纳此处提及的其他建议:
- 将应用程序的URL设置为
http://localhost:8888/laravel-
app/config/local/app.php中的site/my new app/public
- 使用命名路由在整个HTML中保存硬编码URL
{{ Form::open(['url' => 'ducks']) }}