cakephpcakephp-2.0cakephp-model

how to load or use a Model in a Component File especially in Cakephp 2.0?


I need to load a Model in a component to save the Data of that related model in that component itself.

My Component name is ImagemuploadComponent

In this Component I want to load the Attachement Model. I've tried the following code but it did't worked. (Which works fine in cakephp 1.3)

  $Attachment = ClassRegistry::init('Attachment');
  $this->loadModel('Attachment');

Solution

  • Try this code. This will import your model and instantiate.

    After this you can perform any operation as controller.

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