0

I want to be able to seperate my database tables, as i dont want the table getting too big.

when a company registers on my website i would like them to use there own db space.. so in zend i have my model file that connects to db but it will not allow me to make it dynamic. please could some one help me..

db model file to connect to departments that belong to a company

public function company_id(){
  $auth = Zend_Auth::getInstance();
  $company_id = $auth->getIdentity()->comp;
  return $company_id;
}

protected $_comp = $this->company_id();
//$name = '2_departments';
protected $_name = $this->_comp."_departments";
protected $_rowClass = 'Application_Model_Department';

when i use the above code it crashes without error. But if manually code it in and create a php file for every db table it will work file.

manual entry

protected $_name = "2_departments";
protected $_rowClass = 'Application_Model_Department';

if someone could assign that would be awesome.

I have another example

Main class

class Application_Model_Table_Departments extends Teabag_Db_Table {

 public function fetchdepartments() {
       $auth = Zend_Auth::getInstance();
       $company_id = $auth->getIdentity()->comp;

       $select = $this->select()
                      ->from(array('deps'=>$this->_name), array('*'))
                      ->where('deps.is_deleted = 0');

       return $this->fetchAll($select);
   }

}

but then ive extented the class with two other files custom1department.php custom2department.php

class Application_Model_Table_Custom1Departments extends Application_Model_Table_Departments {

protected $_name = "1_departments";
protected $_rowClass = 'Application_Model_Department';

}

and

class Application_Model_Table_Custom2Departments extends Application_Model_Table_Departments {

protected $_name = "2_departments";
protected $_rowClass = 'Application_Model_Department';

}

any ideas on how to make a class dynamic and the class name dynamic?

  • Please post the code and not images of code. – l'L'l Jul 20 '19 at 09:27
  • Sorry give me a min – Stuart Elliot Jul 20 '19 at 09:28
  • Are you still using Zend-Framework version1? ("Zend_Auth" seems to be ZF1.) This could be the reason, your code is not working, when using PHP7. Besides: This would be high safety hazard if you were still using ZF1, as it has reached its EOL long ago. – mdthh Jul 20 '19 at 12:38
  • Oh crap, is they an easy way to update to a newer zend? – Stuart Elliot Jul 20 '19 at 13:18
  • Migration can be quite a hassle. If possible, I recommend starting a new ZF3-Application all together and just try to transfer some of your own code manually. Starting a [new ZF3-App](https://docs.zendframework.com/tutorials/getting-started/overview/) is easy and straight forward. If you decide you still want to migrate your whole ZF1-Application: [This answer](https://stackoverflow.com/a/17329180/514962) might be of help. However, this is a guide on how to migrate ZF1 to ZF2. Currently, ZF3 is the newest version and should be used. – mdthh Jul 20 '19 at 13:47
  • You may consider having a company_id field in a departments table to keep track of each company's department. That way, you will not need any dynamic table-generation functionality. Also, you should try to pass the company_id as an argument to the method/function rather than getting an instance of zend-auth just so as to get the company-id of the logged-in persona. – E. Nwamaife Aug 05 '19 at 12:40

1 Answers1

0

You may consider having a company_id field in a departments table to keep track of each company's department. That way, you will not need any dynamic table-generation functionality.

Also, you should try to pass the company_id as an argument to the method/function rather than getting an instance of zend-auth just so as to get the company-id of the logged-in persona.