简体   繁体   中英

Joining tables in Zend Framework throwing application error

I have this problem after upgrading Zend Framework library to 1.12. It was working fine with version 1.11.

The problem is when I joined two tables, I got this error:

Application error

Exception information:

Message: The specified Table does not have the same columns as the Row

This error is generated from Zend/Db/Table/Row/Abstract.php ( line 356 )

My Table Structure

Members:
  id (int)
  name (varchar)
  age (int)
  family_id (varchar)

Family:
  id (int)
  family_type (varchar)

My Model:

class Model_Member extends Zend_Db_Table_Abstract
{
    public function getAll($params = array())
    {
        $select = $this->select();
        $select->setIntegrityCheck(false);

        $select->from("members", array('name', 'family_id'));
        $select->join('family', 'family.id = members.family_id', array('family_type'));

        $paginator = Zend_Paginator::factory($select);
        $paginator->setItemCountPerPage(20);
        $paginator->setCurrentPageNumber(1);
        $paginator->setPageRange(10);

        return $paginator;
    }
}

And then in my view file

foreach($this->paginator as $row)
{
}

Try this in Your MODEL:

    class Model_Member extends Zend_Db_Table_Abstract
    {
    public function getAll($params = array(), $paged = 1)
   {
    $select = $this->select();
    $select->setIntegrityCheck(false);

    $select->from("members", array('name', 'family_id'));
    $select->join('family', 'family.id = members.family_id', array('family_type'));

    $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
    $paginator = new Zend_Paginator($adapter);
    $paginator->setItemCountPerPage(5)
              ->setCurrentPageNumber((int) $paged);

    return $paginator;
    }
 }

And view:

<?php if($this->data instanceof Zend_Paginator): ?>
                               <?php echo $this->paginationControl($this->data,
                                                                     'Sliding',
                                                                            'pathToController/_paginator.phtml', array('params'=>$params);?>// if you want pass some params. 

Should work on you App, is working on my.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM