Development

#2543 (_compute_public_path handles $sf_relative_url_root not propertly)

You must first sign up to be able to contribute.

Ticket #2543 (new defect)

Opened 1 year ago

Last modified 5 months ago

_compute_public_path handles $sf_relative_url_root not propertly

Reported by: Serg.Sokolenko Assigned to: fabien
Priority: major Milestone:
Component: helpers Version: 1.0.8
Keywords: asset public path relative url Cc:
Qualification: Unreviewed

Description

I have 2 apps: frontend, backend.
Front controllers are organized in such way:

/web/index.php <- frontend
/web/backend/index.php <- backend

The problem is in backend assets: By default, symfony (AssetHelper?) computes assets path relative to application directory, for example, if I call $response->addJavascript('/sf/prototype/js/prototype/prototype.js'); in my backend app, the result will be:

<script type="text/javascript" src="/backend/sf/prototype/js/prototype.js"></script>

What's this? I wanted js from /web directory, not from /web/backend! I thought, "/" in the beginning of path means /web dir!

Looking into _compute_public_path i found, that $sf_relative_url_root is prepended to $source anyway. /branches/1.0/lib/helper/AssetHelper.php

291 	function _compute_public_path($source, $dir, $ext, $absolute = false)
292 	{
...
297 	
298 	  $request = sfContext::getInstance()->getRequest();
299 	  $sf_relative_url_root = $request->getRelativeUrlRoot();
300 	  if (0 !== strpos($source, '/'))
301 	  {
302 	    $source = $sf_relative_url_root.'/'.$dir.'/'.$source;
303 	  }
304 	
...
316 	
317 	  if ($sf_relative_url_root && 0 !== strpos($source, $sf_relative_url_root))
318 	  {
319 	    $source = $sf_relative_url_root.$source;
320 	  }
...

I think, the second condition should be removed. So, after this:
Url begining from "/" will stay as is or else $sf_relative_url_root - will be added to $source.

This is mor natural behavior, because "/js" means - absolute path to /web/js directory and "js" means relative path to app specific js directory.

This issue could be marked as enhancement but I think it is bug.

That should be:

291 	function _compute_public_path($source, $dir, $ext, $absolute = false)
292 	{
...
297 	
298 	  $request = sfContext::getInstance()->getRequest();
299 	  $sf_relative_url_root = $request->getRelativeUrlRoot();
300 	  if (0 !== strpos($source, '/'))
301 	  {
302 	    $source = $sf_relative_url_root.'/'.$dir.'/'.$source;
303 	  }
304 	
...
316 	
 >REMOVED<
...

Change History

02/01/08 17:18:32 changed by utdrmac

$vote++;

We are separating our apps into subdirectories because the 'higher-ups' don't like seeing *.php in the url. (ie: /admin.php/module/action, /members.php/module/action)

All of our link_to(), url_for(), image_tag(), etc are all returning "absolute" paths, relative to the root directory of the controller.

For example. An action located here: /members/module/action, that does a link_to('/cart/view'), should produce a link like this 'http://www.domain.com/cart/view' but instead it produces this 'http://www.domain.com/members/members/cart/view'

The 'absolute' parameter has no effect considering the name 'absolute' should always refer to the / of the domain.

02/01/08 17:20:03 changed by utdrmac

Further, if you do link_to('cart/view'), that should make /members/cart/view but if you do link_to('/cart/view') that should return as stated above because you provided that absolute reference to the / (root) of the domain.

06/18/08 00:25:33 changed by dbrewer

+1

I have exactly the same problem. It needs to be more cleanly possible to have a single set of assets which are shared between multiple applications.

07/07/08 18:42:55 changed by xiong.chiamiov

+1 most definitely. The way symfony currently handles urls like that is the only part about it that drives me nuts.