Move URL-generating code from the view into the controller