我正试图从CakePHP shell发送一封电子邮件,就像你从Controller那样.
下面的大部分代码都是根据这篇关于面包店的日期文章和它的评论改编的.电子邮件正在发送,但该行$controller->set('result', $results[$i]);会抛出以下通知:
注意:未定义的属性:在第813行的/home/jmccreary/www/intranet.sazerac.com/cakephp/cake/libs/view/view.php中查看:: $ webroot
PHP注意:未定义的变量:结果在第2行的/home/jmccreary/www/intranet.sazerac.com/cakephp/app/views/elements/email/text/nea/task_reminder_it.ctp
所以我没有将任何变量传递给我的电子邮件视图.
我怎么能这样做,最好遵循Cake约定?
class NotificationShell extends Shell {
var $uses = array('Employee', 'Task');
function main() {
// run if no action is passed
}
function nea_task_reminder() {
// build Task to Employee relationship
$this->Task->bindModel(array('belongsTo' => array('Employee' => array('className' => 'Employee', 'foreignKey' => 'object_id'))));
$results = $this->Task->find('all', array('conditions' => array('application_id' => 1, 'completed_by_id' => 0), 'contain' => array('Employee' => array('Contact', 'Position'))));
$count = count($results);
if ($count) {
App::import('Core', 'Controller');
App::import('Component', …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用cakephp shell为我的应用程序实现一个任务.该任务涉及运行一个长时间运行的进程(因此需要使用shell).
该函数要求我在Component中使用一个名为CommonComponent的函数
不幸的是,每当我尝试包含该组件时,我得到以下错误PHP致命错误:在/var/www/nginx-test/app/Controller/Component/CommonComponent.php中找不到类'组件'
这是被调用的CronShell类
class CronShell extends AppShell {
public function main() {
$this->out('Hello world.');
// $this->out(phpinfo());
}
public function test()
{
$this->out('Before Import');
App::import('Component', 'Common');
$this->out('Import complete');
// $this->Common=ClassRegistry::init('CommonComponent');
$this->Common =new CommonComponent();
$this->out('Initialization complete');
$this->Common->testCron();
$this->out('FunctionCall complete');
//$this->Common->saveCacheEntry("name","value");
}
}
Run Code Online (Sandbox Code Playgroud)
CommonComponent类存储为app/Controller/Component/CommonComponent.php,如下所示
class CommonComponent extends Component
{
function testCron()
{
$this->out('Hello world from Component.');
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?