如何使用给定的 URL 访问控制器方法


how to access controller method with the given url

我正在使用laravel框架。我需要使用给定 url 的名称访问控制器方法。我的路由代码如下所示:

   <?php
      Route::get('home','HomeController@showWelcome');
   ?>

主控制器.php看起来像这样

   <?php
     class HomeController extends BaseController {
        public function showWelcome()
       {
          return View::make('hello');
       }
     }
   ?>

我的问题是无法访问showWelcome的方法,同时提供类似 http://example.com/home 的网址

但是我可以使用网址访问 http://example.com/index.php/home

如何解决这个问题..谁能帮我做到这一点..提前谢谢。

.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>

这应该是一个评论,但我现在没有足够的声誉。

这是一个重写问题,请查看 http://laravel.com/docs/4.2/installation#pretty-urls 以检查您是否具有正确的配置。

如果您使用的是 apache 并且您的 .htaccess 不起作用,那是因为mod_rewrite已关闭。

希望这有帮助。

首先,您应该打开mod_rewrite。

如果它不起作用,请编辑public/.htaccess并尝试这个:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]