作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试执行 来自我的 Controller 的 shell 通过 AJAX 请求。
在我的 Controller 中:
public function log_import() {
$this->autoRender = false;
App::import('Console/Command', 'AppShell');
App::import('Console/Command', 'IzigetlogShell');
$job = new IzigetlogShell();
$job->dispatchMethod('main');
echo "REPONSE";
}
<?php
App::import('Core', 'Controller');
App::import('Controller', 'Suivis');
class IzilogShell extends AppShell {
public $uses = array('Suivi');
-- DU CODE --
$this->Suivi = new SuivisController();
$this->Suivi->constructClasses();
$exist_date = $this->Suivi->find('first',
array(
'conditions' => array('Suivi.date' => $date_calcul)
));
}
最佳答案
简短的回答是:你没有!
它违反了蛋糕所代表的MVC。
您需要将“共享”代码移动到模型中,并且仅在两种情况下都使用此模型。不是 Controller (这是来自模型和“网络浏览器”的链接/逻辑,而不是你的 shell )。而不是来自 Controller 内部的 shell (因为 shell 是来自模型和“CLI”的链接/逻辑)。
所以:
public $uses = array('Suivi');
无论如何都是用于模型的,而不是用于 Controller 的(顺便说一下文档的特殊性)。
关于shell - CakePHP 2.1.1 : Execute a shell from controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13469048/
我是一名优秀的程序员,十分优秀!