dongyou9721 2014-05-14 05:46
浏览 35
已采纳

Laravel NotFoundHttpException(RouteCollection-> match)

I am new to Laravel and was following a tutorial (https://www.youtube.com/watch?v=Zz_R73eW3OU&list=PL09BB956FCFB5C5FD). I have just installed the latest version of Laravel and am going through the beginning stages of the tutorial. So far (installation, creating a migration) I was doing ok, but now I am stuck at the point of creating new routes.

I have created a controller in app/controllers:

<?php

class Slots_Controller extends Base_Controller{

    public $restful = true;

    public function get_index(){
        return View::make( 'slots.index' );
    }

}

As well as a very minimalist view in the file app/views/slots/index.php

<h1>Slots</h1>

My app/routes file looks like this :

Route::get('/', function()
{
    return View::make('hello');
});

Route::get( '/public/slots', array(
    'uses' => 'slots@index'
) );

I've searched a number of things on the web and here is how far I have come : - i know ideally only the public dir should be in the htdocs, i will be doing that presumably at a further stage of the tutorial. so as of now, my laravel home page is at http://localhost:8888/my_directory.laravel/public/ - i have checked the apache mod-rewrite : it is on and it works well for codeIgniter - i have checked that the .htaccess is as provided by laravel (and as suggested by different posts)

The weird thing is, if i change the routes for the home page like this :

Route::get('/', function()
{
    return 'hello world';
//  return View::make('hello');
});

Nothing changes, i.e. i still get the original welcome page. My understanding is this modification should have simply output "hello world" as the html for the home page.

So it seems that whatever I'm doing in routes.php has no effect whatsoever, as if I was modifying the wrong file or something.

I've spent the most part of an otherwise sunny afternoon on this, any help is much apreciated :)

Thanks,

Tepp

  • 写回答

1条回答 默认 最新

  • dongque3797 2014-05-14 06:37
    关注

    There are many things you are doing wrong here (The best way is to follow the tutorial on Laravel):

    1. In your controller file you are mentioning "Base_Controller", are you sure you have such a file in your controllers directory? (According to my knowledge it should be BaseController)

    2. The Route::get is not defined properly. There are many ways to define a route; however for your case it should be something like this:

      Route::get('slots', array( 'uses' => 'Slots_Controller@get_index' ));

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题