在 symfony 1.4 中,如何从当前操作调用另一个应用程序的操作?
有一个博客文章关于这里:
- http://symfony.com/blog/cross-application-links http://symfony.com/blog/cross-application-links
有一个plugin for it:
- https://github.com/rande/swCrossLinkApplicationPlugin https://github.com/rande/swCrossLinkApplicationPlugin
有一些博文对此进行了解释:
-
http://rabaix.net/en/articles/2009/05/30/cross-link-application-with-symfony http://rabaix.net/en/articles/2009/05/30/cross-link-application-with-symfony
-
http://rabaix.net/en/articles/2009/07/13/cross-link-application-with-symfony-part-2 http://rabaix.net/en/articles/2009/07/13/cross-link-application-with-symfony-part-2
(注意:两者都适用于 symfony 1.2,但它们也应该适用于 1.4)
要将前端路由到后端,只需三个简单步骤:
1. 将以下两种方法添加到您的后端配置中
这些方法读取后端路由,并使用它来生成路由。您需要提供它的链接,因为 php 不知道您如何为其他应用程序配置网络服务器。
.
// apps/backend/config/backendConfiguration.class.php
class backendConfiguration extends sfApplicationConfiguration
{
protected $frontendRouting = null;
public function generateFrontendUrl($name, $parameters = array())
{
return 'http://frontend.example.com'.$this->getFrontendRouting()->generate($name, $parameters);
}
public function getFrontendRouting()
{
if (!$this->frontendRouting)
{
$this->frontendRouting = new sfPatternRouting(new sfEventDispatcher());
$config = new sfRoutingConfigHandler();
$routes = $config->evaluate(array(sfConfig::get('sf_apps_dir').'/frontend/config/routing.yml'));
$this->frontendRouting->setRoutes($routes);
}
return $this->frontendRouting;
}
// ...
}
2. 您现在可以通过以下方式链接到您的应用程序:
$this->redirect($this->getContext()->getConfiguration()->generateFrontendUrl('hello', array('name' => 'Bar')));
3.由于写起来有点繁琐,可以创建一个helper
function link_to_frontend($name, $parameters)
{
return sfProjectConfiguration::getActive()->generateFrontendUrl($name, $parameters);
}
The sfCrossLinkApplicationPlugin https://github.com/rande/swCrossLinkApplicationPlugin这样做,这个,但以更简单的方式,您将能够使用类似于以下的语法:
<?php if($sf_user->isSuperAdmin()):?>
<?php link_to('Edit Blog Post', '@backend.edit_post?id='.$blog->getId()) ?>
<?php endif ?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)