Welcome Guest, Not a member yet? Register   Sign In
Problem -> Acess to CI instance...
#1

[eluser]Multisnet[/eluser]
Hello, I need some help from CI experts. I'm from development team of a a Portuguese Webdesign company. We are using this framework for the first time (in a large scale project). As you could imagine we are facing many conceptual problems. :gulp:

I'll try to explain my doubt as clearly as possible.

I have a model call "new.php", inside that model (using Active Record) I implemented the general methods like getNew, setNew, saveNew, etc.
I want to implement methods for working with newS like getLastNews($number), I'm using a common methodology for object oriented programing which consist in implement this methods as static methods (in this example the method getLastNews($number) is a static method for the class New). The main idea is that the access to database should be processed only in the data layer (models).

Inside the method getLastNews($x) I need to call some CI lib functions like:
Code:
db->limit($x);
db->order_by("Date", $order);

I have a controller for the News in which I call the static method:
Code:
$this->load->model('new');
New::getLastNews($x);

My question is, how to call the CI functions like db->limit(). I couldn't use $this->db->limit() because the system returns this error "Using $this when not in object context". Which is obvious correct because I didn't instantiate any object of type New.

I could not use get_instance() (inside the static method) to access CI because this functions returns the controller and result in the error:
"Undefined property: News_controller::$db".

Have you ever face this problem? Could you make some suggestions please. I need to quickly solve this problem to go on with this project. I don't want to instantiate a object of type new to access to methods like getLastNews(), which deal with multiple object instances.

Thank you in advance...


Messages In This Thread
Problem -> Acess to CI instance... - by El Forum - 06-17-2009, 07:12 PM
Problem -> Acess to CI instance... - by El Forum - 06-17-2009, 09:46 PM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 04:19 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 04:54 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 05:16 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 05:36 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 05:39 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 05:43 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 06:06 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 06:09 AM
Problem -> Acess to CI instance... - by El Forum - 06-18-2009, 06:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB