gpt4 book ai didi

shell - CakePHP 2.1.1 : Execute a shell from controller

转载 作者:行者123 更新时间:2023-12-01 04:01:04 25 4
gpt4 key购买 nike

我正在尝试执行 来自我的 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";

}

还有我的外​​ shell :
<?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)
));

}

但我总是收到相同的错误消息:
PHP fatal error :调用 C:\wamp\www\iziboxLogs\app\Console\Command\IzigetlogShell.php 中未定义的方法 SuivisController::find() 在线 XX

我试图从控制台执行 shell,但我遇到了同样的错误。

有任何想法吗 ?谢谢,马丁

最佳答案

简短的回答是:你没有!

它违反了蛋糕所代表的MVC。
您需要将“共享”代码移动到模型中,并且仅在两种情况下都使用此模型。不是 Controller (这是来自模型和“网络浏览器”的链接/逻辑,而不是你的 shell )。而不是来自 Controller 内部的 shell (因为 shell 是来自模型和“CLI”的链接/逻辑)。

所以:

  • 型号包含所有代码
  • Shell 使用 Model 及其方法
  • Controller 使用模型及其方法

  • => 干燥和清洁

    那么您也不需要单个 App::import(或更好的 App::uses)语句。

    PS:如果你碰巧有很多非模型代码,你也可以在APP/Lib中制作一个Lib,作为你的常用类。

    缴费灵: public $uses = array('Suivi');无论如何都是用于模型的,而不是用于 Controller 的(顺便说一下文档的特殊性)。

    关于shell - CakePHP 2.1.1 : Execute a shell from controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13469048/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com