[英]Laravel 3 - Extending from a controller that extends the Base controller
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)
{
...
You should autoload this in you application start.php folder. 您应该在应用程序start.php文件夹中自动加载它。 If you open that file, and you search for "Base_Controller", you will see something like this:
如果您打开该文件,并搜索“Base_Controller”,您将看到如下内容:
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. Laravel根据所请求的名称加载控制器,并且不会自动加载任何控制器,因为90%的控制器会浪费时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.