I created a few files in app/Lib folder and would like to access one of my models from the library classes:
<?php
App::uses('CrawlerBase','Lib');
App::uses('Deal', 'Model');
class SampleCrawler extends CrawlerBase {
public $uses = array('Deal');
function __construct(){
$this->Deal->create();
However, cake cant seems to find the Deal model and im getting a call to member function create() on a non-object in the model creation line.
Appreciate the help.
Always include models manually if not in a controller/shell:
$this->Deal = ClassRegistry::init('Deal');
and then
$this->Deal->create(); // etc
The advantage: You let Cake load and init the model for you, so if you already did that earlier it will try to reuse it.
EDIT: for the sake of completeness, inside a controller/shell you can simply do
$this->loadModel('Deal');
$this->Deal->create();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With