相关疑难解决方法(0)

面向对象范式中的松耦合和紧耦合有什么区别?

在面向对象的范例中,任何人都可以描述松散耦合和紧耦合之间的确切区别吗?

oop coupling object

256
推荐指数
10
解决办法
29万
查看次数

CakePHP使用Shell cronjob的Email组件

我正试图从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)

php email cakephp

12
推荐指数
2
解决办法
1万
查看次数

使用Cakephp 2+ Shell中的组件

我正在尝试使用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)

有任何想法吗?

components cakephp-2.0

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

cakephp ×1

cakephp-2.0 ×1

components ×1

coupling ×1

email ×1

object ×1

oop ×1

php ×1