I need to do is save some data, then send it back for previewing. The
AJAX function should display it in a modal window. However, I also
need to send back the model ID in the case that the record has only
just been created. That way, the JS function can add the hidden model
ID input so subsequent previews won't save a new record.
Anyway, alerting the response shows I'm getting the JSON object, plus
a 2nd string containing the rendered view. I can't figure out why Cake
is echoing this.
Here's what I've got:
public function admin_preview($id = null)
{
$this->layout = null;
$this->autoLayout = $this->autoRender = false;
$this->viewPath = 'elements/email/text';
Configure::write('debug', 0);
if (!empty($this->data))
{
$data = $this->Newsletter->save($this->data);
}
else if (isset($id))
{
$data = $this->Newsletter->read(null, $id);
}
else
{
return null;
}
$data['Newsletter']['nice_date'] = niceDate(date('Y-m-d'));
$this->set(compact('data'));
echo json_encode(
array(
'id' => $this->Newsletter->id,
'content' => $this->render('newsletter')
)
);
return null;
}
This results in a proper JSON object with id & content, plus the
rendered content again.
I tried return json_encode(...) but, strangely, that results in just
the rendered view. What's going on?!
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
To unsubscribe, reply using "remove me" as the subject.
No comments:
Post a Comment