Welcome Guest, Not a member yet? Register   Sign In
Old way of using classes and CI's way - Confused
#1

(This post was last modified: 12-27-2018, 04:45 PM by dreamweaver.)

I have been trying to improve my code by sticking to OOP concepts. As you can see below my code is using a user class and passing that user class to the models class. 

In code igniter it would be done like this, but this isn't the case since it just gives me an error because of the parameters. 



PHP Code:
$this->load->library('User');
            $this->load->model('User_Model');

            $x = new User($params);
            $y = new User_Model($x);

            $y->insert(); 



My code below:




PHP Code:
$params = array('forename' => $_forename'surname' => $_surname'dob' => $_dob'address' => $_address'telephone' => $_telephone'email' => $_email'password' => $_password);
            
$user 
= new User($params);
            
$user_model 
= new User_Model($user);    

$user_model
->insert(); 
Reply
#2

CI3 wants classes to be named UCfirst, i.e. $this->load->model('User_model'), and with the source code in models/User_model.php.
Once loaded, the model is available as a property, eg $this->user_model, without having to instantiate it.

Your naming confuses me ... I would think that models/User.php would *be* a model for a user.
I might use something like models/Users for the "model" (collection) and models/User for the "entity".
Reply
#3

(12-27-2018, 05:14 PM)ciadmin Wrote: CI3 wants classes to be named UCfirst, i.e. $this->load->model('User_model'), and with the source code in models/User_model.php.
Once loaded, the model is available as a property, eg $this->user_model, without having to instantiate it.

Your naming confuses me ... I would think that models/User.php would *be* a model for a user.
I might use something like models/Users for the "model" (collection) and models/User for the "entity".


Write the code how you would write it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB