Welcome Guest, Not a member yet? Register   Sign In
Global method for all models
#1

I've created a customer model. One of the methods is called check_exists() and this takes a parameter (email address) and checks in the `customer` database table to see if the customer already exists.  This method is called from the customer controller.

Now I've created a user model, and created a new method within also called check_exists().  This takes a parameter (username) and checks in the `user` database table to see if the user already exists.  This method is called from the user controller.

For efficiency I am thinking I could create a global check_exists() function which accepts some additional parameters (database table and field name) and this could be used by all models.  Where would be the place to put this?  I had considered creating a library for it, but I did read that libraries should really be independent and not include database calls.  Is this true?  Is there a better place to put it?  Or should I stick to creating multiple check_exists() methods in each model?

Thanks,
Reply
#2

See the CI Documentation and create a MY_Model.php
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(05-04-2016, 03:44 AM)InsiteFX Wrote: See the CI Documentation and create a MY_Model.php

Thank you, I understand where this is going now Smile
Reply
#4

Thanks, I extended CI_Model using MY_Model and included my method there
Reply
#5

Your welcome
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB