Is this acceptable to be placed in a view?
Kohana (and pro开发者_Python百科bably 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
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.
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.
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);
}
精彩评论