我将CategoryModel
放入models
文件夹时可以正常工作。但是当我把它放在像user
这样的子文件夹中时。它抛出了上述错误。
模型正在控制器内部调用,如图所示..
public function home() {
// titling
$data['title'] = "Price Soldier - Home";
// controlling
$data['current_category'] = "cellphones";
$data['current_brand'] = "all";
$data['current_sorting'] = "latest";
$data['categories'] = CategoryModel::get_all_categories();
$data['brands'] = BrandModel::get_all_brands_by_category("cellphones");
$data['latests'] = ProductModel::get_products("cellphones", "all", "latest");
$data['mvs'] = ProductModel::get_products("cellphones", "all", "most viewed");
$data['plths'] = ProductModel::get_products("cellphones", "all", "price low to high");
$data['phtls'] = ProductModel::get_products("cellphones", "all", "price high to high");
// viewing
return View::make("pages.user.home", $data);
}
所以,简单来说,我如何访问子文件夹中的模型?
答案 0 :(得分:6)
在命令行执行:
composer dump-autoload
或
composer dump-autoload -o
composer dumpautoload -o (dash is optional)
为了更好的优化和速度。
每次在PHP中使用类时,必须是:
1)必需(您可以在代码中执行此操作,但不应该这样做);或
2)自动加载(Composer为您做到了这一点)。
否则它会给你这个你正在看的错误。