• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.