开发者

How do i get the value from array and assign to view in zend frame work

iam executing a stored procedure in php and iam returning an array

       ["record"]=>
   array(1175) {
   [0]=>
array(20) {
  ["Col1"]=>
  string(1) "Mode"
  ["col2"]=>
  string(16) "type"
   }
   }

how do i get the col1 and col2 values from the arra开发者_开发问答y and assign it to the view .what should i say

$view-.results = $result_val['record'];
$view->col1 = ????
$view->col2 = ????


From the controller you assign data to the view using:

$this->view->myData = "something";

Then in the view phtml file:

echo $this->myData;

So in the controller its $this->view and in the view its $this.

In your case assuming your array is called $records:

$this->view->records = $records;

then in your view:

foreach($this->records as $record){
   echo 'Col1 = ' . $record['Col1']. "<BR />";
   echo 'Col2 = ' . $record['Col2']. "<BR />";
}

Hope this helps.


In the Controller:

$this->view->record=$record[0]

In the View:

echo $this->record["col1"]
echo $this->record["col2"]


I am doing like this

// 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);

Then assign the value from controller

$this->view->featuredProducts = $featuredProducts;

then, In the view file.....

<?php foreach($this->featuredProducts As $fpIndex=>$featuredProduct){?>
-----
<?php } ?>


You can use assign method to add an array of variables, for example

$array = array('var1' => 'val1', 'var2' => 'val2');
$this->view->assign($array);

If you do above in view, you can use

$this->view->var1
$this->view->var2

etc

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜