0

I want to generate url in my application from config params. I have folllowing config that I'm processing:

link:
        route_name: article
        route_params: {id: 1}

and my configuration:

->arrayNode('link')
    ->beforeNormalization()
        ->ifString()
        ->then(function ($v) { return [ 'direct' => $v]; })
    ->end()
    ->children()
        ->scalarNode('route_name')->end()
        ->arrayNode('route_params')->end()
        ->scalarNode('direct')->end()
    ->end()
->end()

I'm generating url by:

$this->router->generate($this->config['link']['route_name'],
            $this->config['link']['route_params']);

I don't know how to process array with route_params. Amount and names of params will be different in each routes, so I can't just do:

->arrayNode('route_params')
    ->scalarNode('id')->end()
->end()

I'm getting this error now:

Unrecognized option "id" under "link.route_params"

1 Answer 1

1

Try something like this

   ->arrayNode('route_params')
        ->useAttributeAsKey('name')
        ->prototype('scalar')->end()
    ->end()
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.