1

Zendで送信したいメールの本文変数を作成しようとしています。パーシャルをロードしてモデルに渡し、モデルにパッケージ化して送信することができます。私が抱えている問題は、投稿情報を使用して電子メールを入力するために、$buyerをパーシャルに渡したいということです。

$buyerには私の投稿データがすべて含まれています。そのため、その変数の横に名前、住所、電話番号、およびその他の情報があります。$ body2は、電子メールで送信する前に$buyerからの情報を入力できるようにする単純なHTMLスクリプトです。

// Get the Post Data
$buyer = $request->getPost();
// Creates the body for the email with the users information
$body2  = $this->view->partial('partials/enterpriseContact.phtml');

やってみた-

$body2 = $this->view->partial('partials/enterpriseContact.phtml', $buyer);

しかし、それはうまくいきませんでした。それが違いを生むなら、私はコントローラーの内部で働いています。したがって、完全なコードブロックは次のようになります-

// Get the Post Data
$buyer = $request->getPost();
// Create the body variable by loading the partial for the post card.
$body   = $this->view->partial('partials/postcardEmail/eform1stpostcard.htm');
// Creates the body for the business email with the users information
$body2  = $this->view->partial('partials/enterpriseContact.phtml');
// New Model For Mail Client
$mailUs = new Model_MailUs(); // Instantiate the model to handle Emails
// Use that model to send the email, requires variables, who to send to, and body
$mailUs->sendMail($request->getPost(),  'guest',    $body);  // Sends an email to the user
$mailUs->sendMail($request->getPost(),  'link',  $body2); // Sends an email to us

Zendのコントローラーからパーシャル内に変数を入れるにはどうすればよいですか?

4

2 に答える 2

4

原則として、次のものを使用できるはずです。

// in controller or do this all the way back at bootstrap
$this->view->partial()->setObjectKey('mykey');

// in controller
$renderedContent = $this->view->partial('path/to/partial.phtml', $someData);

次に、部分的に:

<?php 
$someData = $this->mykey
// now use $someData as you like
?>

しかし、率直に言って、私は通常、より冗長なことをすることになります。

// In controller
$renderedContent = $this->view->partial('path/to/partial.phtml', array(
    'mykey' => 'myval',
));

次に、部分的に:

<?php echo $this->mykey ?>
于 2013-01-03T16:49:27.437 に答える
1
$body2  = $this->view->partial('partials/enterpriseContact.phtml', array('buyer' => $buyer));

単語配列を使用してから、上記のように変数コレクションをパーシャルに設定する必要があります。その後、パーシャルにecho $ this-> Buyerと入力して、変数にアクセスできました。

于 2013-01-03T16:45:49.927 に答える