2014-10-10 45 views
0

我在Joomla中制作一个需要向用户发送邮件的自定义组件。我使用该模型从后端管理部分发送邮件。该模式使用此代码:Joomla从后端模型获取SEF前端URL

$btn_link = JURI::root().substr(JRoute::_("index.php?option=com_mymailer&view=messages&email={$myMsg->email}&tid={$myMsg->ticket_id}"); 

然后我用上面的链接的锚上的按钮在邮件正文中,并通过发送JMAIL。但是,到达的链接是非sef链接(因为SEF不适用于后端)。这是我得到的链接:

http://testsite.com/index.php?option=com_mymailer&view=messages&[email protected]&tid=27 

而结果我想是(菜单存在命名为电子邮件):

http://testsite.com/mails/messages/[email protected]&tid=27 

做任何机构有一个想法如何从中获取海基会前端网址后端代码。 在此先感谢。

+0

看到这个[链接](http://docs.joomla.org/Supporting_SEF_URLs_in_your_component) – 2014-10-10 12:47:13

+0

Ofcourse我所看到的页面,但该页面可是没有我的问题或任何接近的任何解决方案。 – Cruising2hell 2014-10-10 16:56:39

回答

0

要实现你想要的东西需要两件大事。首先是让链接端点到模型类在后端扩展自定义消息模型的前端MVC路径。

这将我们带到了第2点。您可以通过mod_menus模块创建一个不会在网站上显示的menutype,并添加一个菜单链接到前端视图,别名中包含您希望别名的内容是。这为Joomla提供了一个参考点。这是快速和肮脏的方法。 “正确的”方法是编写一个router.php脚本并放置在组件的根站点文件夹中。

如果您编写router.php脚本,当使用JRoute :: _()时需要一个警告,这将启用URL自动格式化为SEF格式。如果您不需要,则需要手动格式化链接URL以指向:www.mydomain.com/my-menu-alias

我附加了router.php脚本的链接,它们现在通过以下步骤相关1.

http://docs.joomla.org/Supporting_SEF_URLs_in_your_component http://docs.joomla.org/Search_Engine_Friendly_URLs

2

我知道这很过时,但它在谷歌第一(相关)的结果。 所以你需要站点(前端)路由器和一个ItemID。就这样。 J 1 2.5

//get the frontend Application to create the full object chain 
$siteApp = JApplication::getInstance('site'); 

//now you can use the router for the frontend 
$siteRouter = $siteApp->getRouter(); 

//get the itemid as you wish 
//you can use frontend menu object 
$siteMenu = $siteApp->getMenu(); 

//you need a correct itemid in $yourUri to route correctly 
/* there's a little glitch, maybe with JURI::root so it still uses 
the admin subdir anyways, but simply remove it. 
maybe better to check if it's at the beginning of the string 
but now it's your business */ 

$sefURI = str_replace('/administrator',NULL,$siteRouter->build($yourUri));