Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.