Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL extension uses Route::get() ? maybe URL::site() is better? #3

Closed
buchanae opened this issue May 3, 2010 · 4 comments
Closed

URL extension uses Route::get() ? maybe URL::site() is better? #3

buchanae opened this issue May 3, 2010 · 4 comments

Comments

@buchanae
Copy link

buchanae commented May 3, 2010

Route::get() doesn't work for me, would URL::site() be better? Maybe I'm not using it correctly?

I'm on K03.

@buchanae
Copy link
Author

buchanae commented May 3, 2010

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?)

@aron
Copy link

aron commented May 6, 2010

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

@buchanae
Copy link
Author

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' %}

@aron
Copy link

aron commented May 17, 2010

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

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants