• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Old way of using classes and CI's way - Confused

#1
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, 06: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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.