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

(04-05-2015, 09:01 PM)casa Wrote:
(04-05-2015, 03:23 PM)gadelat Wrote: You are not supposed to use it this way. It reports error because $this->load->model automatically instantiates the model for you into $this->test, you are not supposed to do it yourself. Leave the constructor alone and put that logic into separate method (or access property directly).

OK. but explain why exactly ? and why is not good ? What is the problem with this method ? I inherit a class and I can normally redefine all its methods if necessary.
How i do to make constructors with parameters ? Give an example. I teach in engineering school and say no and not explain why, is not educational.
In POO, it's important to have the possibility to make constructors with parameters.

it is because if you use $this->load->model, codeigniter will instantiate your model automatically "Without" giving any "Parameter" to it. so, it gives you errors..
if you use PDO in Codeigniter, you can call it with $this->db->[your function], because codeigniter wrap PDO in it's database class..
[CMIIW]
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