1

how can i create an url rule, with a named parameter of type array?

now i have this, working:

    'urlManager' => [
        'rules' => [
            'page/<id:\w+>' => 'cms/page/view',
        ],
    ],

to map 'page/welcome' to module=cms, controller=page, action=view, param $id=welcome

now i would like to have the url like this, with a variable number of folder-name parts: /page/folder1/folder2/.../folderN/pagefile

for an action:

function actionPage(array $folders, string $id) {
    // expecting:
    //   $folders == [ 'folder1', 'folder2', ..., 'folderN']
    //   $id      == 'pagefile'
}

don't know how to write the rule. i couldn't find any documentation for the rule-syntax.

workarounds are welcome, too!

2
  • Can you try to rephrase the question, maybe break it up and concentrate on the first case you want to solve? Commented May 12, 2017 at 15:20
  • @dataskills: updated Q. 1. need help writing the rule. 2. if it is not possibly to do it with rules, is there another way? Commented May 12, 2017 at 15:39

1 Answer 1

1

As far as I know the arguments passed to a controller action must be string or int because the controller action parameters work on simple GET parameters.

If you really want to pass an array of folders in a GET request it should be after the route, like: controller/action/id?folder[]=folder1name&folder[]=folder2name

So $id would be in scope in the controller action but you would have to "manually" go through $_GET['folder'] to fetch the variable number of folders that are in the query string.

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

2 Comments

i saw some custom implementations of "urlRule" and was hoping to get one working with arrays. can you point me to the documentation of the urlRule syntax?

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.