0

there is a function get_user_group_ids($user_id), it returns all groups the user belongs. this pings the batch table and gets all the batch_ids. ANd then pings group table and get group_ids corresponding to batch_ids

This is used in event, job and other libraries like eg , get all the job which belongs to my batch. here i need to call this function to get my group ids.

because this is a common function, i have doubt whether to create common library or model

4
  • why not put it in a core model? like MY_Model or something. Commented Sep 29, 2011 at 9:15
  • ok, i can do that. is it good idea to write in common library> Commented Sep 29, 2011 at 9:25
  • I don't quite get what you mean. Commented Sep 29, 2011 at 9:57
  • you said to use model. i just want to know reason for not to use library, so that i can clearly understand the different between model and library. Commented Sep 29, 2011 at 10:24

2 Answers 2

1

If this function is fetching the ID's from a database or other external datasource then a model is the way to go :)

Sign up to request clarification or add additional context in comments.

Comments

0

I've been in a similar situation where I needed to share a model (an abstract collection of methods) between a framework (CakePHP in my case) and shell scripts for batch jobs. To do so I found that the simplest method was to create a CakePHP model like any other model EXCEPT it didn't extend the base (parent) framework model class (CI_Model in your case). The advantage with this was that I was still able to "load" (initiate) the class from CakePHP using the same conventions as any other framework model but was able to use the same model (the actuall file) in batched shell scripts without needing to load anything extra.

I'm pretty certain the same is possible in CI (although I'm not a heavy CI user):

# the model definition /application/models/CustomModel.php class CustomModel { public function __construct() {} # ... public function get_user_group_ids( $id ) {} # ... } # from inside the a controller method: $this->load->model( 'CustomModel' ); $this->CustomModel->get_user_group_ids( $id ); # ... # from inside the shell scripts: require_once( YOUR_CI_PATH . '/application/models/CustomModel.php' ); $obj = new CustomModel(); $obj->get_user_group_ids( $id ); # ... 

Hope this helps, Cheers

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.