how to put the view in zend framework

This is my Controller coding in zend framework

public function homeAction() {

    $storage = new Zend_Auth_Storage_Session();
    $data = $storage->read();
    if (!$data) {
    $this->view->storeid = $data->storeid;
    $iExtStoreId = $data->storeid; // admin storeid

    $db = Zend_Db_Table::getDefaultAdapter();
    $sql = "SELECT storeId FROM stores where extStoreId= '$iExtStoreId' ";

    $result = $db->fetchAll($sql);
    $sStoreId = $result[0]['storeId'];
    if (strlen($sStoreId) >= 32) {
        $sql = "select * from voucherRedemptions where storeId='$sStoreId'";

        $result2 = $db->fetchAll($sql);
    } else {
        $result2 = array();
    echo "<table border='1'>

    if (count($result2) > 0) {
        foreach ($result2 as $row) {
            echo "<tr>";
            echo "<td>" . $row['redemptionId'] . "</td>";
            echo "<td>" . $row['voucherId'] . "</td>";
            echo "<td>" . $row['storeId'] . "</td>";
            echo "<td>" . $row['redemptionTime'] . "</td>";
            echo "</tr>";
    } else {
        echo "<tr><td colspan='4'>Data not found </td></tr>";

    echo "</table>";

now I want to keep the view code in view folder home.html what i can do ?


Don't echo all that stuff in the controller. That's what the view is for.

After setting all the viewvariables do:


And print all the stuff there.

Also note that the Zend Framework has pretty good documentation available.

I'm not too up-to-speed with Zend Framework, but going on PeeHaa's answer and my sketchy knowledge, I'd guess your controller would look like this:

class YourController {

    public function indexAction() {
        $view = new Zend_View();
        $view->someVar = 'Some Value.';

And then in your admin.phtml template:

<!-- should output "Some Value." -->
<p><?php echo $this->someVar; ?></p>

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.