2016-01-24 15 views
1

我正在爲Codeigniter翻譯庫中的自定義類,但我遇到了這個問題。codeigniter將對象庫傳遞到另一個庫

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

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

我使用的庫加載器改變了requireconstruct

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

,但現在我需要這個功能轉換,但我不知道在哪個模式下能做到這一點

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; 
} 

回答

1

這裏是可以幫助

進行管理控制器邏輯 和AMODEL和Bmodel

負載這些模型管理控制器內部

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); 
} 

這樣

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; 
} 

bmodel.php函數中這樣amodel.php文件中可以調用bmodel.php功能可以是這樣的

function get_todos($a){ 

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

} 
相關問題