0

I am trying to build a simple URL router that loads predefined urls and settings into an array. Then I need to push it all to a function with a static variable so I can store all the urls and settings in a uniform way.

The array looks like:

Array
(
    [index] => Array
        (
            [#title] => Home
            [#access] => user_access
            [#callback] => page_index
        )

    [admin/dashboard] => Array
        (
            [#title] => Dashboard
            [#access_callback] => user_access
            [#page_callback] => page_dashboard
        )

    [admin/stats]

Then I want to push the data from the array into a function:

route('path/path', #callback, #title, #access);

I am trying to build the foreach loops but I can't get passed this mess:

foreach($routes as $path => $array) {
    foreach($array as $key => $value) {

    }
 route($path, );
}

I feel like I am approaching this the wrong way. Any help would be helpful. Thanks

1 Answer 1

1

What I think you want to do is just break it down to that first array. So:

foreach ( $routes as $path => $array ) {

    route ( $path, $array );

}

Then within route, you would work with the array by just referring to the title, access and callback keys. Like $array['title'] to do something with the title. Just my take on it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.