tags:

views:

44

answers:

3

Kohana (and probably other frameworks) allow you get a route and echo its URL, creating routes that are easy to maintain.

<a href="<?php echo url::base() . Route::get('contact'); ?>">Contact</a>

Is this OK to have in the view, or should I assign it to a variable, and then pass the view the variable?

Thanks

+2  A: 

You aren't performing logic here. This is perfectly acceptable.

Of course your view code would be a bit cleaner if you created a variable in your controller, but this really is fine IMHO.

Jacob Relkin
Cool, I always did this but after read Matt's comment to [my answer](http://stackoverflow.com/questions/2393051/favourite-kohana-tips-features/2474278#2474278), I started passing them to view. But it cluttered up my view variables considerably and didn't seem necessary.
alex
A: 

I find such a concatenation unnecessary. It seems url::base() going to be used in every link on the site. Why not to have a method to add it automatically? Something like Route::url("contact")
And usage of such a construct in the template is OK.

Col. Shrapnel
A: 

You can create a function or static method for generating urls:

public static function url($routename, array $params = NULL)
{
   return url::base().Route::get($routename)->uri($params);
}
biakaveron
Calling `url::url()` won't be confusing?
alex
It can be another helper, like `common::url()` or `core::url()` :) Usually I dont modify/extend system classes for newfeatures.
biakaveron