Php 如何从数组中获取值并分配给zend frame work中的视图
iam在php中执行存储过程,iam返回数组Php 如何从数组中获取值并分配给zend frame work中的视图,php,zend-framework,Php,Zend Framework,iam在php中执行存储过程,iam返回数组 ["record"]=> array(1175) { [0]=> array(20) { ["Col1"]=> string(1) "Mode" ["col2"]=> string(16) "type" } } 如何从数组中获取col1和col2值并将其分配给视图 .我该怎么说 $view-.results = $result_val['record']; $view-&
["record"]=>
array(1175) {
[0]=>
array(20) {
["Col1"]=>
string(1) "Mode"
["col2"]=>
string(16) "type"
}
}
如何从数组中获取col1和col2值并将其分配给视图
.我该怎么说
$view-.results = $result_val['record'];
$view->col1 = ????
$view->col2 = ????
从控制器,您可以使用以下命令将数据指定给视图:
$this->view->myData = "something";
然后在视图phtml文件中:
echo $this->myData;
因此,在控制器中是$this->view,在视图中是$this
在本例中,假设数组名为$records:
$this->view->records = $records;
那么在你看来,
foreach($this->records as $record){
echo 'Col1 = ' . $record['Col1']. "<BR />";
echo 'Col2 = ' . $record['Col2']. "<BR />";
}
foreach($this->记录为$record){
回显'Col1='.$record['Col1'].“
”;
回显'Col2='。$record['Col2'].“
”;
}
希望这有帮助。从控制器中,您可以使用以下方式将数据分配给视图:
$this->view->myData = "something";
然后在视图phtml文件中:
echo $this->myData;
因此,在控制器中是$this->view,在视图中是$this
在本例中,假设数组名为$records:
$this->view->records = $records;
那么在你看来,
foreach($this->records as $record){
echo 'Col1 = ' . $record['Col1']. "<BR />";
echo 'Col2 = ' . $record['Col2']. "<BR />";
}
foreach($this->记录为$record){
回显'Col1='.$record['Col1'].“
”;
回显'Col2='。$record['Col2'].“
”;
}
希望这有帮助。在控制器中:
$this->view->record=$record[0]
他认为:
echo $this->record["col1"]
echo $this->record["col2"]
在控制器中:
$this->view->record=$record[0]
他认为:
echo $this->record["col1"]
echo $this->record["col2"]
我就是这样做的
// this is to set the view files path
$view = $this->view;
$view->addHelperPath(APPLICATION_PATH . "/../themes/" . $siteName."/views/helpers");
$view->addScriptPath(APPLICATION_PATH . "/../themes/" . $siteName."/views/scripts"); // or addBasePath(), if you prefer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setView($view);
然后从控制器分配值
$this->view->featuredProducts = $featuredProducts;
然后,在视图文件中
<?php foreach($this->featuredProducts As $fpIndex=>$featuredProduct){?>
-----
<?php } ?>
-----
我就是这样做的
// this is to set the view files path
$view = $this->view;
$view->addHelperPath(APPLICATION_PATH . "/../themes/" . $siteName."/views/helpers");
$view->addScriptPath(APPLICATION_PATH . "/../themes/" . $siteName."/views/scripts"); // or addBasePath(), if you prefer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setView($view);
然后从控制器分配值
$this->view->featuredProducts = $featuredProducts;
然后,在视图文件中
<?php foreach($this->featuredProducts As $fpIndex=>$featuredProduct){?>
-----
<?php } ?>
-----
例如,您可以使用assign方法添加变量数组
$array = array('var1' => 'val1', 'var2' => 'val2');
$this->view->assign($array);
如果在视图中执行上述操作,则可以使用
$this->view->var1
$this->view->var2
等
希望这有帮助。例如,您可以使用assign方法添加变量数组
$array = array('var1' => 'val1', 'var2' => 'val2');
$this->view->assign($array);
如果在视图中执行上述操作,则可以使用
$this->view->var1
$this->view->var2
等
希望这能有所帮助。@lznogood:如何从我的数组中为“某物”赋值problem@Someone如果这仍然没有帮助,我建议您发布更多代码并使用代码格式化程序。发布/编辑问题时,它是001001按钮。@lznogood:如何从我的问题数组中为“某物”赋值problem@Someone如果这仍然没有帮助,我建议您发布更多代码并使用代码格式化程序。当你发布/编辑你的问题时,它是001001按钮。