Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在组件文件中加载或使用模型,尤其是在Cakephp 2.0中?_Cakephp_Cakephp 2.0_Cakephp Model - Fatal编程技术网

如何在组件文件中加载或使用模型,尤其是在Cakephp 2.0中?

如何在组件文件中加载或使用模型,尤其是在Cakephp 2.0中?,cakephp,cakephp-2.0,cakephp-model,Cakephp,Cakephp 2.0,Cakephp Model,我需要在组件中加载一个模型,以将相关模型的数据保存在该组件本身中 我的组件名称是ImagemuploadComponent 在这个组件中,我想加载附件模型。 我尝试了下面的代码,但没有成功。(在cakephp 1.3中运行良好) 试试这个代码。这将导入您的模型并实例化 在此之后,您可以作为控制器执行任何操作 App::import('Model','Attachment'); $this->Attachment = &new Attachment(); $this->Atta

我需要在组件中加载一个模型,以将相关模型的数据保存在该组件本身中

我的组件名称是ImagemuploadComponent

在这个组件中,我想加载附件模型。 我尝试了下面的代码,但没有成功。(在cakephp 1.3中运行良好)


试试这个代码。这将导入您的模型并实例化

在此之后,您可以作为控制器执行任何操作

App::import('Model','Attachment');
$this->Attachment = &new Attachment();
$this->Attachment->save($your_data);

这个答案是错误的,给出错误建议的原因不止一个:App::import不推荐用于加载类,应该使用App::uses(),对于模型,在这种情况下应该是ClassRegistry::init('Attachment');问题是2.0而不是1.3。
App::import('Model','Attachment');
$this->Attachment = &new Attachment();
$this->Attachment->save($your_data);