colapiombo
colapiombo

Reputation: 189

codeigniter pass object library to another library

I am tring to translate my custom classes in a library for Codeigniter but I have this problem.

require_once "a.php";
require_once "b.php";

function __construct() {    
     $this->b = new b();
}

I changed the require and construct using the library loader.

function __construct() {
   $this->CI =& get_instance();
   $this->CI->load->library('a');
   $this->CI->load->library('b');
}

but now I need to convert this function but I don't know in which mode a can do that

public function addRecipient($first,$second){
   $a= new a($first);  // ??? new library a ?
   $a->header = 1;
   $a->set($second);     
   $this->b->add($a);     // passing object library a???
   return $a;
}

Upvotes: 1

Views: 507

Answers (1)

synan54
synan54

Reputation: 658

here is a logic that may help

make a admin controller and Amodel and Bmodel

load these model inside admin controller

class admin extends CI_Controller{

    function __construct()
    {

    $this-load>model('amodel');
    $this-load>model('amodel');

    }

 function index($first,$second){
 $a = $this->amodel->addRecipient($first,$second)
 $this->data['a'] = $a;
 $this->load->view('index',$this->data);
 }

so inside amodel.php file you can call bmodel.php functions like this

public function addRecipient($first,$second){
$a = new stdClass();
$a->header = 1;
$a->first = $first; 
$a->second= $second;
$a = $this->bmodel->get_todos($a);  
return $a;
}

inside bmodel.php function can be something like this

function get_todos($a){

$a->third =  $a->first + $a->second
return  $a;

 }

Upvotes: 1

Related Questions