doulie0178 2014-05-26 21:35
浏览 59

试图在cakephp中获取一个控制台脚本来访问控制器

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.

  • 写回答

2条回答 默认 最新

  • dqwh2717 2014-05-26 22:38
    关注

    If you need use other model use:

    $this->loadModel('ModelName')

    Read more: loadModel in CakeBook

    Also, I don't recommend using controller action in shell. Use model methods instead. (In case if you don't have in model things that you need - move them to model [this is their place].)

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效