Feb 10 2009

Linking within the action, model and templates

Category: RoutingJeff @ 2:27 pm
      

I continuously find myself looking these up, so I’m posting them here. Routing in Symfony is super easy, but remembering the proper method for calling upon routes can be mind scrambling.

Generating links in a Template

link_to('Anchor Text', 'action/method?id=123', array('class' => 'some-class', 'target' => '_blank'))

Below, the second parameter determines whether or not to send an absolute URL

url_for('action/method?id=123', true)

Generating links in an Action or Controller

$this->getController()->genUrl('action/method?id=123')

Generating links from within the Model

Below, the second parameter of genUrl() determines whether or not to send an absolute URL

sfContext::getInstance()->getController()->genUrl('action/method?id=123', true)

Leave a Reply