Welcome Guest, Not a member yet? Register   Sign In
Calling function within Model.
#1

[eluser]grahoom[/eluser]
Hello,

I was wondering - I have a Model, that I am using for navigation.

I am wanting to create another function that creates a heirachical menu structure from pages that are stored in my DB.

at present I have pages that have a field in the table that can be set to say if the page is a container (and also a field in a page that can be set to state what the pages parent is)

So For example

Page 1
Page 2
Page 3
- Page 4
- Page 5
- Page 8
Page 6
Page 7

Where Page 4 and 5 Parent is Page 3 (and Page 1, 2, 3 ,6 ,7 parent is effectively 0 - as I am using 0 as a reference to site root)

What I want to do is create a recursive function that is called within my model so that I can create this heirachical menu structure.

How do I go about calling a function that is within a Model from another function that is within the same Model (is this actually possible?)

I tried just using

generate_navigation($navigation_root)

from within a function in my model but I get the error

Fatal error: Call to undefined function generate_navigation()

so How do you call a function that is in a Model from that same Model ?
#2

[eluser]GSV Sleeper Service[/eluser]
like this
Code:
class My_model extends Model
{
    function test1()
    {
        return "I am test 1";
    }

    function test2(){
        // call the test1 function in this model
        return $this->test1();
    }
}

sorry it's such a contrived example, but it's just to illustrate that you have to use $this->[whatever] to access methods/properties in the same class.
#3

[eluser]grahoom[/eluser]
I did try that - but I am getting the same error...

ah ok - I have it working now... many thanks.




Theme © iAndrew 2016 - Forum software by © MyBB