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

为什么我得到 p>

 类'Search_Controller'而不是 在执行此操作时找到
  code>  pre> 
 
 

: p>

  class Snippets_Controller extends Search_Controller {
 
public $ restful = true;  
 
公共函数get_index()
 {
 $ snippets = Snippet :: all(); 
 $ categories = Categorie :: all(); 
 
返回View :: make('snippet.index'  ) - > with(array(
'snippets'=> $ snippets,
'categories'=> $ categories,
'active_categorie'=> Session :: get('active_categorie_id')
)  
); 
} 
  code>  pre> 
 
 

搜索控制器: p>

 类Search_Controller扩展Base_Controller {
 \  n protected static function build_html_for_search_results($ search_results)
 {
 ... 
  code>  pre> 
  div>

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.