0

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

alex
  • 479,566
  • 201
  • 878
  • 984

3 Answers3

2

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
  • 161,348
  • 33
  • 346
  • 320
  • 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 Sep 27 '10 at 05:17
0

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.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

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
  • 5,493
  • 1
  • 16
  • 20