phpuser12
phpuser12

Reputation: 355

how to include zend phtml file to other phtml file

I'm use zend framework 1.

and I need to include phtml file inside another file and send parameter to first file.

Ex:

I have indexController.php

and I have $numberOfItem defined inside the controller

I need to render (include) menu.phtml inside index.phtml and send $numberOfItem varible to it

Thanks

Upvotes: 3

Views: 6201

Answers (2)

janenz00
janenz00

Reputation: 3310

Its Zend partial.

In the IndexController, you will pass the numberOfItem value to the corresponding view as usual.

    $this->view->numberOfItem = $numberOfItem;

Then, in the index.phtml :

    echo $this->partial('viewfolder/menu.phtml', array('numberOfItem' => $this->numberOfItem));

in the menu.phtml:

     echo $this->numberOfItem;

The viewfolder in the partial's path will be the same as the relative folder from the "view/scripts". For example, even if both your index.phtml and menu.phtml are in the same folder "application/views/scripts/index", you need to pass the path to partial as index/menu.phtml

Upvotes: 1

Osama Jetawe
Osama Jetawe

Reputation: 2705

you can use zend partial to do that

in your index.phtml do

echo $this->partial('yourfolder/menu.phtml', array('numberOfItem' => $numberOfItem));

and in your menu.phtml you can read the print the variables using

$this->numberOfItem

Upvotes: 7

Related Questions