CodeIgniter Forums
sub functions in class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: sub functions in class (/thread-18932.html)



sub functions in class - El Forum - 05-22-2009

[eluser]Guntars[/eluser]
Hi,
I have a problem with functions in classes

here is an example
Code:
class Admin extends Controller {
var $admin;
var $id;

    function Admin()
    {
        
        parent::Controller();
        
    
    }
function someffunction(){
function subfunction(){
$result=$this->db->get('articles');
$result=$result->result();
return $result;

}

$newresult=$this->somefunction()->subfunction();
print_r($newresult);
}

become as error, I try to find in here and in google, but can't really find if possible to get sub functions with data.

I know have nice thing &get;_instance, but my question if it's possible to get without this.


sub functions in class - El Forum - 05-22-2009

[eluser]Dam1an[/eluser]
Sorry, I'm not quite sure what you're trying to acheive here, and why you'd want a funtion in a function?
Also, you should really move the db calls to a model Smile


sub functions in class - El Forum - 05-22-2009

[eluser]Guntars[/eluser]
Just an Idea is, In my CMS website have a plugins facility, and I want to live these separately from root code. In general everything it's fine, but some times I need some extra function. I can solve this If I use &get;_instance. and all data loads fine, but I not really like this method.

I'm not sure if you understand what I mean, but the main question is, if it's possible to get function from function with $this method.

I know this need very few times.


sub functions in class - El Forum - 05-22-2009

[eluser]SpooF[/eluser]
You might be able to do that if your somefunction returned an object of a class, but you wouldn't be able to write your functions like that.


sub functions in class - El Forum - 05-22-2009

[eluser]Jondolar[/eluser]
Functions that are not part of a class are global. PHP does not allow a class definition to expand across files. I don't think you can do what you want.