We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Very strange! May be a bug of 2.0? (Wrong behavior of baseuri)

The base uri is '/' in config.php, the below code works very well in 1.3.4.

{{ link_to('javascript:deleteCategory(' cat.getId() ')', 'delete', 'class':'btn btn-default') }}</li>

But, in 2.0, phalcon will generate wrong codes:

<a href="/javascript:deleteCategory(118)" class="btn btn-default">deelte</a></li>

There is a slash / before javascript.

edited Mar '15

I think this not a bug.

link_to method works based on the base uri but in this case you don't need baseuri and It's better to generate url manually or write your custom helper and add it to you volt compiler.

Personaly I prefer this way:

{% set jslink = 'javascript:deleteCategory(' ~ cat.getId() ~ ')' %}
<li><a href="{{ jslink }}" class="btn btn-default">delete</a></li>


5.4k

Thanks, but I think it's a bug. Same code works very well in 1.3.4.

I need the baseuri in development mode, but when I release it into production mode, I need to make it baseuri to '/'.

I think this not a bug.

link_to method works based on the base uri but in this case you don't need baseuri and It's better to generate url manually or write your custome helper and add it to you volt compiler.

Personaly I prefer this way:

{% set jslink = 'javascript:deleteCategory(' ~ cat.getId() ~ ')' %}
<li><a href="{{ jslink }}" class="btn btn-default">delete</a></li>

I agree with Aboozar, not a bug, it's just the intended behaviour for relative URLs you create using the Tag::linkTo. The Javascript you're feeding it is viewed as a relative URL.

The Javascript you put in the href should really go in an onclick attribute or be assigned on page load, as a bonus, any element will do in that case, not just links :)