2011-02-25 5 views
1

私はcronジョブを介してシェルスクリプトを実行しています。それは正しく電子メールを送信します。しかし、私はできないように見えるデータベースから電子メールテンプレートにデータを渡すことができるようにしたい。ここでCakePHP 1.3 cronで実行中のシェル - データを電子メールテンプレートに渡す

シェル

App::import('Core', 'Controller'); 
App::import('Component', 'Email'); 

class ExampleShell extends Shell { 

var $uses = array('User'); 

function main() { 

$users = $this->User->find('all'); 

$this->Controller =& new Controller(); 
$this->Email =& new EmailComponent(null); 
$this->Email->initialize($this->Controller); 

$this->Email->reset(); 
$this->Email->to = 'xx<[email protected]>'; 
$this->Email->subject = "Subject"; 
$this->Email->template = 'example'; 
$this->Email->sendAs = "both"; 
$this->Controller->set('users', $users); 
$this->Email->send(); 

} 

} 

変数$ユーザーがexample.ctpファイルで利用できるようには見えないのですか?シェルスクリプトのデータをテンプレートに渡すにはどうしたらいいですか?

+0

この行を変更してください:var $ uses = array( 'User');これまで:var $ users = array( 'User'); –

+0

ありがとう、私はそれを試みたが、私は今、次のエラーが表示されます:未定義のプロパティ:exampleShell :: $行/ '$ users = $ this-> User-> find(' all ');' – Dave

+0

何をお話していますか? $ usesは、モデル – Aziz

答えて

1

私はそれが誰かを役に立てば幸い方法

class ExampleShell extends Shell { 
    var $uses = array('User'); 
    var $Controller = null; 

    function __construct(&$dispatch) { 
    App::import('Core', 'Controller'); 
    App::import('Controller', 'App'); 
    $this->Controller = & new Controller(); 

    App::import('Component', 'Email'); 
    $this->Email = new EmailComponent(); 
    $this->Email->initialize($this->Controller); 
    parent::__construct($dispatch); 
    } 

    function main() { 
    $users = $this->User->find('all'); 

    $this->Controller =& new Controller(); 
    $this->Email =& new EmailComponent(null); 
    $this->Email->initialize($this->Controller); 

    $this->Email->reset(); 
    $this->Email->to = 'xx<[email protected]>'; 
    $this->Email->subject = "Subject"; 
    $this->Email->sendAs = "both"; 
    $this->Controller->set('users', $users); 
    $this->Email->send(null, 'template_1'); 
    } 
} 

を次でそれを行うことができました。

テンプレートがテキストバージョンの場合は、app/views/elements/email/html/template_1.ctpapp/views/elements/email/text/template_1.ctpになるようにしてください。 app/views/layouts/email/html/default.ctpapp/views/layouts/email/text/default.ctp

+0

に対処する権利を与えます。これは完全に機能します!ありがとうございました。 – jmorganmartin

関連する問題