在 Zend 中,模型被添加到视图中:
//In a controller
public function indexAction() {
//Do some work and get a model
$this->view->model = $model;
}
我们可以轻松地检查视图中是否存在“模型”(我为此使用了 simpletest):
//In a unit test
public function testModelIsSetInView() {
//Call the controllers index action
$this->assertTrue(isset($this->controller->view->model));
}
但是,测试“值”也不起作用:
//In a unit test
public function testModelValue() {
//Call the controllers index action
//Both of these return null, though I'd like to access them!
$this->assertNull($this->controller->view->model);
$this->assertNull($this->controller->view->__get('model'));
}
如何获得(或至少测试)控制器已设置有效模型?