Development

SecuringDevFrontend (diff)

You must first sign up to be able to contribute.

Changes between Version 5 and Version 6 of SecuringDevFrontend

Show
Ignore:
Author:
l2k (IP: 88.65.240.214)
Timestamp:
10/11/07 11:52:20 (10 years ago)
Comment:

code formatting

Legend:

Unmodified
Added
Removed
Modified
  • SecuringDevFrontend

    v5 v6  
    1212Using a vhost one can set the application, environment and debugging mode. The frontend code would need to be modified as follows: 
    1313{{{ 
     14#!php 
     15<?php 
    1416define('SF_ROOT_DIR',     realpath(dirname(__FILE__).'/..')); 
    1517define('SF_APP',          isset($_SERVER['SF_APP'])?$_SERVER['SF_APP'] : 'frontend'); 
    60621) Add a constant in the given front controllers that enables the host rewriting: 
    6163 
     64{{{ 
     65#!php 
     66<?php 
    6267define('SF_REWRITE_ASSET_HOST', true); 
     68}}} 
    6369 
    64702) Add a filter that rewrites the location (for most applications there will be a need to initialize the session, making sure that non authenticated users are directed at the right page, that the language/country cookie is set properly etc., which seems like a goof location for this code): 
    6571 
     72{{{ 
     73#!php 
     74<?php 
    6675class initSessionFilter extends sfFilter 
    6776{ 
    7382  public function execute($filterChain) 
    7483  { 
    75     if ($this->isFirstCall()) { 
     84    if ($this->isFirstCall()) 
     85    { 
    7686      $context  = $this->getContext(); 
    7787      $request  = $context->getRequest(); 
    7989      $action   = $context->getActionStack()->getLastEntry()->getActionInstance(); 
    8090 
    81       if (defined('SF_REWRITE_ASSET_HOST') && SF_REWRITE_ASSET_HOST) { 
     91      if (defined('SF_REWRITE_ASSET_HOST') && SF_REWRITE_ASSET_HOST) 
     92      { 
    8293        $asset_host = sfConfig::get('app_config_rewrite_asset_host'); 
    83         if (substr($asset_host, 0, 4) === 'http') { 
     94        if (substr($asset_host, 0, 4) === 'http') 
     95        { 
    8496          $request->setRelativeUrlRoot($asset_host); 
    85         } elseif (preg_match('/s(\/.+\/)(.*)/', $asset_host, $matches)) { 
     97        } 
     98        elseif (preg_match('/s(\/.+\/)(.*)/', $asset_host, $matches)) 
     99        { 
    86100          $request->setRelativeUrlRoot(preg_replace($matches[1], $matches[2], $request->getRelativeUrlRoot())); 
    87         } else { 
     101        } 
     102        else 
     103        { 
    88104          $request->setRelativeUrlRoot($request->getRelativeUrlRoot().$asset_host); 
    89105        } 
    93109  } 
    94110} 
     111}}} 
    95112 
    961133) Add 'app_config_rewrite_asset_host' to your app.yml file 
    97114 
     115{{{ 
    98116all: 
    99117  config: 
    101119#   rewrite_asset_host:         's/admin\./' 
    102120    rewrite_asset_host:         '/../web' 
     121}}} 
    103122 
    104123Remember that you can have different configuration settings per environment and per server (following the above guidelines). There is a problem with this solution however if the no_script_tag feature is disabled, since in that case the url helpers will use the $request->getRelativeUrlRoot() to construct the url. In that case you also need to do some further hacking: 
    1061254) First you need to store the original relative url root in a constant before modifying the value in your filter. Then you need to open up and store lib/symfony/controller/sfWebController.class.php in your application lib directory and modify the genUrl() method. Look for the call to getRelativeUrlRoot() and change the section of the code as follows: 
    107126 
     127{{{ 
     128#!php 
     129<?php 
    108130$url = ''; 
    109131if (!sfConfig::get('sf_no_script_name')) 
    115137  $url = (defined('RELATIVE_ROOT_URL')) ? RELATIVE_ROOT_URL : $sf_relative_url_root; 
    116138} 
     139}}}