【问题标题】:While in zend framework在zend框架中
【发布时间】:2014-06-08 22:06:22
【问题描述】:

大家早上好,我尝试使用zend框架查询以下表单但我不能,我想使用while,因为foreach已经这样做了,留下我的代码看看我错在哪里:

模型.php

<?php

class Application_Model_Datas 
{



    public function listar()
    {
$db = Zend_Db_Table::getDefaultAdapter();

$select = $db->select()
             ->from('album');

return $db->fetchAll($select);

    }
}

索引.phtml

<?php
//And your view looks like this.
while ($select = $this->datos){
   print_r($results);
}


?>

控制器.php

    <?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
                     $table = new Application_Model_Datas(); 

                     $this->view->datos = $table->listar();
    }


}

问题是它没有显示任何错误或数据或任何东西

【问题讨论】:

    标签: php zend-framework while-loop


    【解决方案1】:

    你的代码没有意义/效果

    <?php
    
    //And your view looks like this.
    while ($select = $this->datos){
       print_r($results); //Normally you get in an infinite loop
    }
    
    ?>
    

    你只需要遍历一个简单的数组:

    $i = 0;
    
    while($i < count($this->datos)) {
        print_r($this->datos[$i++]); //Getting current element, and incremeting counter
    }
    

    希望对你有帮助。

    【讨论】:

    • 非常感谢您的朋友,正在努力做到这一点!问候!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 2013-02-23
    • 2011-01-29
    • 2013-05-22
    • 2017-04-12
    • 1970-01-01
    相关资源
    最近更新 更多