So, I have been trying to get a console script working in CAKEPHP. But it won't let me access controllers using the $uses
member.
I have tried assigning an array to $uses, and a non array to $uses, both outside and inside of a method inside of my JobManagerClass, and nothing works.
Right now, I have...
<?php
class JobManagerShell extends AppShell {
public $uses;
public function main() {
$this->_processJobs();
}
public function _processJobs() {
$this->uses = array("Job");
$jobs = $this->Job->find("all");
foreach ($jobs as $job) {
if ($job["is_running"] == 1) exit;
}
foreach ($jobs as $job) {
$id = $this->Job->id = $job["id"];
$this->Job->saveField(array("Job" => array("is_running" => 1)));
exec($job["command"] . "2> errors.txt");
$errorsFile = fopen("errors.txt");
$errorsText = fread($errorsFile);
fclose($errorsFile);
$this->Job->delete($this->Job->id);
$this->uses = array("Error");
$this->Error->save(array("Error" => array("job_id" => $i, "error" => $errorsText)));
}*/
}
}
?>
and that gives the error:
PHP Fatal error: Class 'AppModel' not found in /home/webdev/webroot/Cake/lib/Cake/Utility/ClassRegistry.php on line 185
If I try changint the line that says:
$this->uses = array("Job");
to
$this->uses = "Job";
I get the error:
Notice Error: Undefined property: JobManagerShell::$Job in [/home/webdev/webroot/Vehicle_Scrapper/lib/Cake/Console/Shell.php, line 491]
I've been trying to find an answer to this, but I can't seem to.