我在ZF应用程序中返回XML时遇到问题.我的代码:
class ProjectsController extends Gid_Controller_Action
{
public function xmlAction ()
{
$content = "<?xml version='1.0'><foo>bar</foo>";
header('Content-Type: text/xml');
echo $content;
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过以下方法:
class ProjectsController extends Gid_Controller_Action
{
public function xmlAction ()
{
$content = "<?xml version='1.0'><foo>bar</foo>";
$this->getResponse()->clearHeaders();
$this->getResponse()->setheader('Content-Type', 'text/xml');
$this->getResponse()->setBody($content);
$this->getResponse()->sendResponse();
}
}
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向如何实现这一目标?
我正在切换表单以使用View Script作为装饰器.到目前为止我看到的示例在View脚本中执行以下操作:
<td><label for='textEmail'>Email:</label></td>
<td><?php echo $this->element->textEmail; ?></td>
Run Code Online (Sandbox Code Playgroud)
我想找到一种方法让文本显示在Form对象的标签中.
class RegisterForm extends Zend_Form {
public function init () {
$this->setAction('')
->setMethod('post')
->setAttrib('id','formRegister');
$this->addElement('text', 'textEmail', array('label' => 'Email: '));
$oEmail = $this->getElement('textEmail')
->setRequired(true)
->addFilter('StringTrim')
->addValidator('EmailAddress');
$oEmail->setDecorators(array('ViewHelper', 'Errors'));
$this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/RegisterForm.phtml'))));
}
}
Run Code Online (Sandbox Code Playgroud)
以上是我的表单对象的定义方式.有人知道如何访问定义的标签值吗?可能采用以下格式?
<?php echo $this->element->textEmail->label; ?>
Run Code Online (Sandbox Code Playgroud)
当然这不起作用.:p谢谢〜