Welcome Guest, Not a member yet? Register   Sign In
Where to put classes of business logic?
#16

[eluser]Dready[/eluser]
Hello,

that's really not a correct usage of helpers. I see two more elegant solutions :

Autoload your libraries with autoload functions

Perhaps you already know it, something like :

helpers/autoload_helper.php
Code:
function __autoload($class_name) {
    if ( is_file(APPPATH.'/libraries/'.$class_name.'.php') ) {
          require_once APPPATH.'/libraries/'.$class_name.'.php';
    }
}

And in config/autoload.php
Code:
$autoload['helper'] = array('autoload');

Create a factory class

If you have many business classes, using a factory pattern can help you to have a common way to load all libraries.

libraries/factory.php
Code:
class factory {
  function create($class_name,$your,$parameters) {
    // security checks on $class_name here
    ...

    require_once APPPATH.'/libraries/'.$class_name.'.php';

    return new $class_name($your,$parameters);
  }
}

in controllers :
Code:
$this->load->library('factory');
$myobject =& $this->factory->create('myObject','foo','bar');


Messages In This Thread
Where to put classes of business logic? - by El Forum - 09-25-2008, 01:58 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 02:23 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 02:26 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 02:41 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 02:48 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 02:58 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 03:20 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 03:23 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 03:26 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 03:35 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 04:01 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 07:11 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 07:29 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 07:30 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 08:34 AM
Where to put classes of business logic? - by El Forum - 09-25-2008, 02:26 PM
Where to put classes of business logic? - by El Forum - 09-25-2008, 03:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB