Welcome Guest, Not a member yet? Register   Sign In
model's constructor with parameters
#1

Hello,
I want to create a model which extends CI_MODEL and in my constructor, iwant to pass some parameters.
Exemple :
class Test extends CI_Model
{
private $items ;

public function __construct( $params)
{
parent::__construct();
$this->items = $params ;
}
public function getItems() { return $this->items ; }
}

When i load my model in my controler or everywhere else i do this :
$this->load->model('Test');
$r = new Test('toto') ;

i have this message : "Missing argument 1 for Test::__construct()".
i had try this :
class Test extends CI_Model
{
private $items ;

public function __construct( $params = '')
{
parent::__construct();
$this->items = $params ;
}
public function getItems() { return $this->items ; }
}
and then when i do it :
$this->load->model('Test');
$r = new Test('toto') ;
echo $r->getItems () ; // 'toto'
No problem Smile
Is my method is the right way to practice with CodeIgniter ?
Thanks for your answers Smile
Reply


Messages In This Thread
model's constructor with parameters - by casa - 04-05-2015, 10:33 AM
RE: model's constructor with parameters - by casa - 04-05-2015, 09:01 PM
RE: model's constructor with parameters - by s4if - 04-06-2015, 12:18 AM
RE: model's constructor with parameters - by casa - 04-06-2015, 01:57 AM
RE: model's constructor with parameters - by casa - 04-06-2015, 02:23 AM
RE: model's constructor with parameters - by casa - 04-06-2015, 04:55 AM
RE: model's constructor with parameters - by casa - 04-07-2015, 04:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB