Zend传递变量来查看

时间:2013-06-10 11:54:06

标签: php zend-framework

在使用laravel和其他框架之前,我是Zend的新手。所以我有一个Zend项目需要修改,问题是我无法将变量从控制器传递到视图。

控制器:

$temp_id = $this->_request->getParam ('temp_id');

if($temp_id){
    $data = $card_temp_model->getSingle('*', 'id='.(int)$temp_id);

    if(!$data['icon_id'])
        $data['icon_id'] = 9;
    if(!$data['icon2x_id'])
        $data['icon2x_id'] = 10;
    $data['template_only']=1;

    $form->setDefaults($data);
}

$locations = $card_location_model->getAll('*', 'card_id='.(int)$temp_id);

$this->view->locations = $locations;
$this->view->form = $form;

我的观点文件:

<?=
    die(print_r($this->locations));
?>

我无法在我的视图文件中获取位置。有人可能会解释我为什么?

2 个答案:

答案 0 :(得分:0)

要将变量分配给ZF中的视图,您应该使用此代码

$this->view->var = "some text"; // where "some text" may be variable or everthing else.

您的问题在于放置文件。如果使用目录结构,可以更改ZF目录结构。

APPLICATION
  controllers
     NameController.php
Views
  Name
     Index.html

然后在Index.html中echo $var;

在NameController.php中

创建IndexAction()方法并将变量赋值给视图。

要显示此控制器,请使用domain.com/name/domain.com/name/index

这一切都是为了让它有效。

答案 1 :(得分:0)

在控制器......

$this->view->foo = 'sample string or content';

在视图中使用escape方法来防止xss问题。

echo $this->escape($this->foo);
相关问题