Question

I'm making an AJAX call in my symfony project, so it has an sf_format of 'js'. In the actionSuccess.js.php view, I call get_partial to update the content on the page. By default it looks for the partial in 'js' format since the sf_format is still set as 'js'. Is it possible to override the sf_format so that it uses the regular 'html' partial that I already have (so that I don't have to have two identical partials)?

Was it helpful?

Solution

I have had a similar issue.

I looked through the code, and get_partial doesn't give you any scope to change the format looked for ... guess you could modify the code to make that possible if you needed to.

I instead went for switching the request format - also not ideal in my opinion. But better than editing the symfony files.

To do this in the controller:

$request->setRequestFormat('html');

or in the view

$sf_context->getRequest()->setRequestFormat('html');

In both cases, if you want to set this back afterwards, you can retrieve the existing value using getRequestFormat().

OTHER TIPS

if your looking for a more sustainable solution, you could listen to the view.configure_format and set the sfPHPView extension in your appflication configuration.

// in apps/api/config/apiConfiguration.class.php
public function configure() {
  $this->dispatcher->connect('view.configure_format', array($this, 'configure_formats'));
}

public function configure_formats(sfEvent $event) {
  // change extension, so our module templates and partials 
  // for xml do not need the .xml.php extension
  $event->getSubject()->setExtension('.php');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top