Phalcon PhP - how to use named routes inside a controller

168

I'm having trouble finding how to get the Urls from named routes inside a Phalcon PhP controller. This is my route:

$router->add(
    '/admin/application/{formUrl:[A-Za-z0-9\-]+}/{id:[A-Za-z0-9\-]+}/detail',
    [
        'controller' => 'AdminApplication',
        'action' => 'detail' 
    ]
)->setName("application-details");

I want to get just the Url, example: domain.com/admin/application/form-test/10/detail . With the code below I can get the html to create a link, the same result of the link_to.

$url = $this->tag->linkTo(
    array(
        array(
            'for' => 'application-details',
            'formUrl' => $form->url,
            'id' => $id
        ), 
        'Show'
    )
);

The result I want is just the Url. I'm inside a controller action. I know it must be really simple, I just can't find an example. Can you help me?

Thanks for any help!

706

Answer

Solution:

You should use the URL helper. Example:

$url = $this->url->get(
    [
        'for' => 'application-details', 
        'formUrl' => $form->url,
        'id' => $id,
    ], 
    [
        'q' => 'test1',
        'qq' => 'test2',
    ]
);

You can pass second array for query string params if needed.

According to your route definition, the above should output something like:

/admin/application/form-url/25/detail?q=test1&qq=test2

More info of Generating URIs in the docs.

People are also looking for solutions to the problem: php - if condition in html editable table

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.