Welcome Guest, Not a member yet? Register   Sign In
(Solved) how to load/call a function within a class?
#1

[eluser]Unknown[/eluser]
In order to load a function in a controller from a model is easy but how do you call a function within a class in a controller?

class Crud extends controller {

function index () {

????? how to load a function get_all ?????

}

function get_all () {

$mydata = $this->db->get('users');
foreach ($mydata->result() as $row) {
$aa= $row->username;
echo $aa;
}
}

}
#2

[eluser]2think[/eluser]
Using standard PHP convention:

$this->get_all();

* Note: You said it's easy to load a function in a controller from a model but the conventional CI arrangement is to call a model's functions from a controller; hence the name - controller.
#3

[eluser]Unknown[/eluser]
[quote author="2think" date="1291347328"]Using standard PHP convention:

$this->get_all();

* Note: You said it's easy to load a function in a controller from a model but the conventional CI arrangement is to call a model's functions from a controller; hence the name - controller.[/quote]


Thank you!
#4

[eluser]2think[/eluser]
You're welcome and thank YOU for posting [solved] in the subject, its proper etiquette but I have even at times been more than guilty of not doing same.




Theme © iAndrew 2016 - Forum software by © MyBB