dpzlz08480 2013-07-16 12:28
浏览 37
已采纳

Laravel 3 - 从扩展基本控制器的控制器扩展

Why do I get a

Class 'Search_Controller' not found

when doing this:

class Snippets_Controller extends Search_Controller {

public $restful = true;

public function get_index()
{
    $snippets = Snippet::all();
    $categories = Categorie::all();

    return View::make('snippet.index')->with(array(
        'snippets' => $snippets,
        'categories' => $categories,
        'active_categorie' => Session::get('active_categorie_id')
        )
    );
}

The Search Controller:

class Search_Controller extends Base_Controller {

    protected static function build_html_for_search_results($search_results)
    {
...
  • 写回答

1条回答 默认 最新

  • dtt78245 2013-07-16 14:31
    关注

    You should autoload this in you application start.php folder. If you open that file, and you search for "Base_Controller", you will see something like this:

    Autoloader::map(array(
        'Base_Controller'       => path('app').'controllers/base.php'
    ));
    

    The only thing you have to do is add the search controller there:

    Autoloader::map(array(
        'Base_Controller'       => path('app').'controllers/base.php',
        'Search_Controller'     => path('app').'controllers/search.php'
    ));
    

    And that should do the trick.

    Laravel loads controllers based on the name that's requested, and it doesn't autload any of the controllers, as it would be a waste of time for 90% of the controllers.

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

报告相同问题?