Welcome Guest, Not a member yet? Register   Sign In
Basic controller problem help
#1

[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
#2

[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();
#3

[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




Theme © iAndrew 2016 - Forum software by © MyBB