CodeIgniter Forums

Full Version: (Solved) how to load/call a function within a class?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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;
}
}

}

El Forum

[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.

El Forum

[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!

El Forum

[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.