0

I would like to configure view.yml per environment.

In production:

default:
  http_metas:
    content-type: text/json

In dev:

default:
  http_metas:
    content-type: text/html

I need this because I want to debug json response with web debug toolbar. So, I basically need to set content type of response per environment. Is it possible to do it yml? If not, what's the right place to hook into?

Dziamid
  • 11,225
  • 12
  • 69
  • 104

2 Answers2

1

You cannot do it in view.yml without rewriting the entire view config handler. I suppose there are a couple of alternatives for this specific example:

  • You could use the ysfDimensionsPlugin which allows you to specify different dimensions with different config files.

  • You could achieve this by adding or extending a filter in the filter chain, I suppose I would do this by extending sfRenderingFilter.

If however, you just want to inspect JSON output, why not use Firebug or Web Inspector?

Gerry
  • 6,012
  • 21
  • 33
  • No, I would like to inspect database calls, etc.. in the web debug toolbar, which is only injected into the response if it is html content-type. – Dziamid Aug 24 '11 at 11:47
0

Open file lib/symfony/config/sfViewConfigHandler.class.php

now replace "mergeConfig" function with below and your problem will be solved :)

  protected function mergeConfig($myConfig)
  {
    // merge javascripts and stylesheets
    $myConfig['all']['stylesheets'] = array_merge(isset($myConfig['default']['stylesheets']) && is_array($myConfig['default']['stylesheets']) ? $myConfig['default']['stylesheets'] : array(), isset($myConfig['all']['stylesheets']) && is_array($myConfig['all']['stylesheets']) ? $myConfig['all']['stylesheets'] : array());
    unset($myConfig['default']['stylesheets']);

    $myConfig['all']['javascripts'] = array_merge(isset($myConfig['default']['javascripts']) && is_array($myConfig['default']['javascripts']) ? $myConfig['default']['javascripts'] : array(), isset($myConfig['all']['javascripts']) && is_array($myConfig['all']['javascripts']) ? $myConfig['all']['javascripts'] : array());
    unset($myConfig['default']['javascripts']);

    // merge default and all
    $myConfig['all'] = sfToolkit::arrayDeepMerge(
      isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(),
      isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array(),
      isset($myConfig[sfConfig::get('sf_environment')]) && is_array($myConfig[sfConfig::get('sf_environment')]) ? $myConfig[sfConfig::get('sf_environment')] : array()
    );
    unset($myConfig['default']);
    $this->yamlConfig = $myConfig;
  }
ManuPK
  • 11,623
  • 10
  • 57
  • 76