2014-10-10 79 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));