Php 要查看的Zend pass变量

Php 要查看的Zend pass变量,php,zend-framework,Php,Zend Framework,我是Zend的新手,在使用laravel和其他框架之前。所以我有一个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[

我是Zend的新手,在使用laravel和其他框架之前。所以我有一个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));
?>


我无法获取视图文件中的位置。也许有人可以解释一下原因?

要在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

这就是让它工作的全部

在控制器中

$this->view->foo = 'sample string or content';
在视图中,使用escape方法防止xss问题

echo $this->escape($this->foo);

分配是可以的,你使用什么控制器和什么动作?你确定你的视图在正确的目录中吗?视图是否显示时没有适当的值?控制器:Pass\u IndexController,操作:formAction,视图是/applications/modules/Pass/views/scripts/index有点确定,但不是100%确定,第一次使用zend,所以可能我在某个错误的地方做错了什么;)是视图显示不带值。如果我转储$this,我可以看到locations数组在某个地方,但数组太大了,我无法通过它找到我的location arraywell的确切位置,您使用的是哪个版本的ZF?domain.com/en/pass/index/form/temp_id/170所以控制器是pass,动作是index。看起来我在正确的控制器中,我使用的是正确的视图。什么是en?是控制器吗?什么是行动/模块?您是否使用自己的路由?