Welcome Guest, Not a member yet? Register   Sign In
Library, Controller, Model, Helper, or Plugin?
#1

[eluser]Dave Stewart[/eluser]
Hi there,

For my application, I've a large number of SQL select statements I want to store in an array, to be used across controllers / requests. Essentially they will deliver different table views, based on reports a user might request.

So my question is: what would be the best construct to store them in?

Should I create a library, helper, or should the requests be part of a model that is loaded in each time, or something else?

Thanks for your help,
Dave
#2

[eluser]libnac[/eluser]
I think you must use models.

you can use models in this way:

yourmodelmodel.php

class Yourmodel extends Model {
function Yourmodel() {..}

function view1() {

$select_sql = "table1.*, .... ";

return executeQry($select_sql);
}

function view2() {
...
}

...

function executeQry($select_sql) {

$this->obj->db->select($select_qry);
$query = $this->obj->db->get();
if($query->num_rows()>0 )
return $query->result();
}

}
}
or something like this...

And you can load this model in your controller constructor.

class Yourcontroller extends Controller {
function Yourcontroller() {
$this->load->model("yourmodelmodel")
}
}

I hope this will be useful for you
#3

[eluser]Dave Stewart[/eluser]
Thanks Liberto.

Actually, I'm not actually modelling data with this method, just storing SQL queries which will provide data that can be represented as a model.

In the meantime, I just created a standard class that I loaded in as a library, and this seems to work fine.

Mind you, the physical end result between using a model or a library would seem to be no different - you still call them the same way: $this->model_name->function()

More opinions welcome!

Thanks,
Dave
#4

[eluser]Seppo[/eluser]
Are you just storing the SQL string? You can use a config file for that.




Theme © iAndrew 2016 - Forum software by © MyBB