Closed buchanae closed 14 years ago
apologies if I'm just misunderstanding what the url extension should do.
possibly you could drop this in favor of the helper extension, which allows url.site (I think?)
Route::get() works just fine for me. How are you using the tag?
{% url {route_name}, {parameters} %}
For example to load the edit action on the posts controller you would use the following:
{% url "default", ["controller":"posts", "action":"edit", "id":"my-post"] %}
Hope that helps?
Cheers,
Aron
I see, thanks.
Should that tag be called "route" then? Since it relates directly to the Route helper, that makes more sense to me anyway.
I was using this tag, trying to link to a static asset e.g.
{% url '/img/foo.png' %}
or, in general, I find it easier, simpler, clearer to just use URL format (especially if the template coders are not backend devs, and shouldn't need to know controller, action, etc)
e.g. {% url 'posts/edit/1' %}
Ideally you should be able to rename the tags by simply creating your own Twig_URL_TokenParser
and redefining the getTag()
method to return 'route'. However unfortunately the Twig module doesn't conform to the Kohana design principals with it's tag implementation.
For your static assets you could either create a tag module for the URL class or a simpler solutions would be to define a "base_url" variable in your controller set to URL::base(TRUE, TRUE)
and use this in your views.
<img src="{{ base_url }}/img/foo.png" />
I'd argue that you should always use the controllers and actions in your views even if it does make them appear more complex as it decouples the site URLs from the templates. This means that in the future should you decide to modify your applications routes, for example adding a prefix or swapping the parameters around, all your templates will still generate correct links and not require any modification.
Cheers,
Aron
Route::get() doesn't work for me, would URL::site() be better? Maybe I'm not using it correctly?
I'm on K03.