CodeIgniter Forums
Basic controller problem help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Basic controller problem help (/showthread.php?tid=7396)



Basic controller problem help - El Forum - 04-07-2008

[eluser]Unknown[/eluser]
I have set up a controller called testme.php that contains the following code:
Code:
<?php
class Testme extends Controller
{
    function index()
    {
        echo '<p>index function</p>';
        _myFunc();
    }
    
    function _myFunc()
    {
        echo '<p>private function called from index function</p>';
    }
}
?&gt;

I access this using
Code:
http://www.mydomain.com/index.php/testme/

I would expect this to render the following:
Code:
<p>index function</p>
<p>private function called from index function</p>

However, it does not. It renders only
Code:
<p>index function</p>

Am I just misunderstanding how this should work, or is something broken?

Thanks,
Philip


Basic controller problem help - El Forum - 04-07-2008

[eluser]richthegeek[/eluser]
you are trying to call the general function "_myFunc()" rather than the method "Testme::_myFunc()"

To call the method from within its parent class, prepend the method name with $this->, like so:
Code:
$this->_myFunc();



Basic controller problem help - El Forum - 04-07-2008

[eluser]Unknown[/eluser]
Thanks.

While I've been working with PHP for a while, I've never really used it with an object oriented approach before, so It's taking me some time to adjust.

I appreciate the help.

PJ