(I am new on this list, so sorry if the question was already submitted. I have searched on archives !)
I wanted to create an helper to simply make a link to an application from another (inside the same symphony project). So I supposed the simple thing was to get the sfContext object related to the application I wanted to link, and use the sfControlleur to generate the Url.
My code is : include_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR. $appname.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); $myControl = sfController::newInstance(sfConfig::get('sf_factory_controller', 'sfFrontWebController')); $myControl->initialize(sfContext::getInstance()); return $myControl->genUrl($internal_uri, false);
but, as getInstance is a singleton, I get the context of my current application. Is there a way to get this instance ?
> (I am new on this list, so sorry if the question was already > submitted. I have searched on archives !)
> I wanted to create an helper to simply make a link to an application > from another (inside the same symphony project). So I supposed the > simple thing was to get the sfContext object related to the > application I wanted to link, and use the sfControlleur to generate > the Url.
I think this is limitation not only in symfony but in PHP overall.
you wrote 18.06.2007, 07:39 pm:
> Hi Olivier, > This is a known limitation of symfony. > The singleton pattern won't allow you > to get 2 different sfContext > object at the same time. > Fabien
As far as inter-application linking is concerned, this is really not easy to do in symfony 1.0 because you have 2 singleton: sfContext and sfRouting.
I'm working hard to remove this limitation and I hope a future release of symfony will be able to create link for another application of the same project our of the box.
> (I am new on this list, so sorry if the question was already > submitted. I have searched on archives !)
> I wanted to create an helper to simply make a link to an application > from another (inside the same symphony project). So I supposed the > simple thing was to get the sfContext object related to the > application I wanted to link, and use the sfControlleur to generate > the Url.
> As far as inter-application linking is concerned, this is really not > easy to do in symfony 1.0 because you have 2 singleton: sfContext and > sfRouting.
> I'm working hard to remove this limitation and I hope a future release > of symfony will be able to create link for another application of the > same project our of the box.
Thank you for the answer.
I'am just discovering the heart of symfony and I suppose it will be difficult for me to help a lot. So, to build my helper, I will parse the routing.yml of the other app.
> > (I am new on this list, so sorry if the question was already > > submitted. I have searched on archives !)
> > I wanted to create an helper to simply make a link to an application > > from another (inside the same symphony project). So I supposed the > > simple thing was to get the sfContext object related to the > > application I wanted to link, and use the sfControlleur to generate > > the Url.
I've managed to create links to other apps using project-wide config settings. Of course, this doesn't use any of the routing rules, but it works in many cases. It sounds like your new helper, Olivier, will be much more robust if it parses the routing.yml of the other app. For a simple solution, I found this works. Hope it helps.
1. Add appropriate URLs in the project's config/app.yml file. As there are different settings used depending on the environment, you can put the full URL here and have it automatically use the right setting...
2. In your templates, whenever you need to link between apps, you can use this: <?php echo link_to('Admin Site', sfConfig::get('app_url_backend')) ?> or <?php echo link_to('Public Site', sfConfig::get('app_url_frontend')) ?>
>> As far as inter-application linking is concerned, this is really not >> easy to do in symfony 1.0 because you have 2 singleton: sfContext and >> sfRouting.
>> I'm working hard to remove this limitation and I hope a future >> release >> of symfony will be able to create link for another application of the >> same project our of the box.
> Thank you for the answer.
> I'am just discovering the heart of symfony and I suppose it will be > difficult for me to help a lot. So, to build my helper, I will parse > the routing.yml of the other app.
> Olivier
>> Fabien
>> Olivier Mansour wrote: >>> hello
>>> (I am new on this list, so sorry if the question was already >>> submitted. I have searched on archives !)
>>> I wanted to create an helper to simply make a link to an application >>> from another (inside the same symphony project). So I supposed the >>> simple thing was to get the sfContext object related to the >>> application I wanted to link, and use the sfControlleur to generate >>> the Url.
On 18 Jun., 17:46, Fabien POTENCIER <fabien.potenc...@symfony-
project.com> wrote: > As far as inter-application linking is concerned, this is really not > easy to do in symfony 1.0 because you have 2 singleton: sfContext and > sfRouting.
> I'm working hard to remove this limitation and I hope a future release > of symfony will be able to create link for another application of the > same project our of the box.
Hi Fabien.
Just wanted to inform you that I have started working on implementing a dependency injection solution (or is it a service locator?? ;-) ) inspired by Garden (I posted about it before). I think I can commit it at the end of the week to my mahono branch so people can test it.
At this time I implemented it as additional feature (some new methods in sfContext) without any BC issues. But it is very easy to replace the factory.yml in the future. Unlike Garden I implemented a Yaml driver today that makes setting up objects really easy and turns this approach into a cool symfony feature. And I call it 'tone' instead of 'bean' - I thought "symfony tone" is much cooler than "Java Bean" ;-)
I don't know what you've done so far in that direction, Fabien, but I could imagine that this could even help with getting this inter- application linking problem solved. For example by prefixing tone names: