Jump to content

Multiple table relationships in Zend


ShaolinF

Recommended Posts

Hi Guys

I have been doing some DB mapping to link two tables to no avail. Everytime I run the code I get the following error:

 

Message: File "Role.php" does not exist or class "Role" was not found in the file
    
    Stack trace:
    
    #0 C:\wamp\www\zend\library\Zend\Db\Table\Row\Abstract.php(867): Zend_Db_Table_Row_Abstract->_getTableFromString('Role')
    #1 C:\wamp\www\uw\application\models\admin\User.php(56): Zend_Db_Table_Row_Abstract->findDependentRowset('Role')
    #2 C:\wamp\www\uw\application\controllers\AdminController.php(110): Application_Model_Admin_User->getUsers()
    #3 C:\wamp\www\zend\library\Zend\Controller\Action.php(513): AdminController->usersAction()
    #4 C:\wamp\www\zend\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('usersAction')
    #5 C:\wamp\www\zend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #6 C:\wamp\www\zend\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
    #7 C:\wamp\www\zend\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
    #8 C:\wamp\www\uwi\public\index.php(26): Zend_Application->run()
    #9 {main}

 

Code & DB below:

 

application/models/admin/User.php

    <?php
    
    class Application_Model_Admin_User extends Zend_Db_Table_Abstract
    {
     protected $_name = 'user';
     protected $_dependentTables  = array('Role');
      
     public function getUsers()
     {  
      $rows = $this->fetchAll($this->select()->where('active = ?', 1));
      $rows1 = $rows->current();
      $rows2 = $rows1->findDependentRowset('Role');
      return $rows2;
     }
    }

 

application/models/admin/Role.php

    <?php
    
    class Application_Model_Admin_Role extends Zend_Db_Table_Abstract
    {
     protected $_name = 'role';
     protected $_referenceMap = array (
     'Role' => array(
      'columns'           => array('id'),
      'refTableClass'     => 'User',
      'refColumns'        => array('role_id')
     );
    
    }

 

DB tables

 

    CREATE TABLE role (
       id integer auto_increment NOT NULL,
       name varchar(120),
       PRIMARY KEY(id)
    );
    
    CREATE TABLE user (
       id integer auto_increment NOT NULL,
       username varchar(120),
       PRIMARY KEY(id),
       FOREIGN KEY(role_id) REFERENCES role(id)
    );

Link to comment
https://forums.phpfreaks.com/topic/200468-multiple-table-relationships-in-zend/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.