Php 如何在Zend Framework 2中传递和显示变量
我想学习Zend Framework 2,我已经在我的机器上安装了它,我到达了欢迎页面,这很好,所以当我查看它的结构时,它在CodeIgniter或Laravel中有很大的不同,我的问题是我想在我的Php 如何在Zend Framework 2中传递和显示变量,php,zend-framework,zend-framework2,Php,Zend Framework,Zend Framework2,我想学习Zend Framework 2,我已经在我的机器上安装了它,我到达了欢迎页面,这很好,所以当我查看它的结构时,它在CodeIgniter或Laravel中有很大的不同,我的问题是我想在我的index.phtml中显示一些文本或字符串。在我的IndexController.php中,我得到了这个 public function indexAction() { $sample = 'sample string'; // this is what I want to pass in
index.phtml
中显示一些文本或字符串。在我的IndexController.php
中,我得到了这个
public function indexAction() {
$sample = 'sample string'; // this is what I want to pass in my index.phtml
return new ViewModel();
}
索引.phtml
索引.phtml
中显示它//Controller.php
public function indexAction() {
$data = 'Sample data'; // this is sample string that will display in my index.php
return view('home',$data);
}
//View
<?php
echo $data; // it will print the string in my $data(variable);
?>
//Controller.php
公共函数索引(){
$data='Sample data';//这是将显示在my index.php中的示例字符串
返回视图('home',$data);
}
//看法
我是Zend Framework 2的新手,我对这个框架没有任何想法。帮帮我,伙计们。提前感谢您帮助莫解决我的问题 在Zend 2中,将要在视图中使用的任何变量传递到
ViewModel
或返回数组:
public function indexAction() {
$sample = 'sample string'; // this is what I want to pass in my index.phtml
return new ViewModel(array(
"sample" => $sample
));
}
或:
然后,您可以访问索引中的$sample
。phtml
如下:
<?php echo $this->sample ?>
数组键将始终是视图的属性名称
有关更多信息,请参见:
在Zend 2中,将要在视图中使用的任何变量传递到
ViewModel
或返回数组:
public function indexAction() {
$sample = 'sample string'; // this is what I want to pass in my index.phtml
return new ViewModel(array(
"sample" => $sample
));
}
或:
然后,您可以访问索引中的$sample
。phtml
如下:
<?php echo $this->sample ?>
数组键将始终是视图的属性名称
有关更多信息,请参见:
谢谢您的回答,谢谢您的关注。谢谢您的回答,谢谢您的关注。