簡體   English   中英

joomla 2.5錯誤頁面

[英]joomla 2.5 error page

我為缺少的網址創建了一個錯誤頁面(404頁)。 這是通過標准方式或模板中的error.php文件完成的。

錯誤頁面工作正常,可以正確重定向到Joomla文章。 我的問題是我想捕獲用戶單擊的鏈接,然后生成404頁面。 我的想法是將一些代碼放在error.php頁面的頂部,該頁面通過電子郵件向我發送了缺少的頁面:

            <?php
            defined('_JEXEC') or die;
            $app = JFactory::getApplication(); 
            $menu = $app->getMenu();
            $menuItem = $menu->getItems( 'link', 'index.php?option=com_example&view=reporting', true );
            $ref = JRoute::_('index.php?Itemid='.$menuItem->id);
            $mailer = JFactory::getMailer();
            $config = JFactory::getConfig();
            $sender = array( 
                $config->getValue( 'config.mailfrom' ),
                $config->getValue( 'config.fromname' ) );

            $mailer->setSender($sender);
            $recipient = array( 'me@mysite.com' );

            $mailer->addRecipient($recipient);

            $body   = "Missing page is ".$ref;
            $mailer->setSubject('404 Error Generated by your site');
            $mailer->setBody($body);

            $send = $mailer->Send();
            if ( $send !== true ) {
                echo 'Error sending email: ' . $send->__toString();
            } else {
                echo 'Mail sent';
            }

            header("Location: http://www.domain.com/404-page.html"); /* Redirect browser */
            exit();?>

但是我無法獲得商品ID。 我可以獲得引用頁面$ _SESSION [“ origURL”] = $ _SERVER [“ HTTP_REFERER”]; 但這沒有用,因為它是我要查找的缺少頁面的ID。

有任何想法嗎? 我想知道是否需要創建一個會話變量,該變量在每次單擊菜單項並訪問它時都會更新,但似乎有點過頭了。

謝謝

艾倫

多虧了大衛·T,他為我指明了正確的方向。 我重新編碼,就可以了! 我已經在代碼中添加了一些注釋,因此希望它可以幫助其他人為Joomla 2.5構建錯誤頁面(在3.0中沒有嘗試過)

再次感謝David T

艾倫

            <?php
            defined('_JEXEC') or die;

            //Get reffering Id
            $referer = JURI::getInstance($_SERVER['HTTP_REFERER']);
            $ref = $referer->hasVar('Itemid')?$referer->getVar('Itemid'):JSite::getMenu()->getActive()->id;

            //Get the title and other menu details as needed form db

            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query = "SELECT * FROM `#__menu` WHERE id = ".$ref."";

            $db->setQuery( $query );
            $results = $db->loadObjectList();
            $holdingArray = array();

            if(count($results)) {
                foreach($results as $r) {
                    array_push ($holdingArray,$r->title,$r->menutype) ;
                    }
            }       

            // Set up mailer and get site name and other details
            $mailer = JFactory::getMailer();
            $config = JFactory::getConfig();
            $sender = array( 
            $config->getValue( 'config.mailfrom' ),
            $config->getValue( 'config.fromname' ) );
            $siteName = $config->getValue( 'config.sitename' );

            $mailer->setSender($sender);
            $recipient = array( 'youremail@yourdomain.com' );

            $mailer->addRecipient($recipient);

            $body   = "The menu item clicked was: ".$holdingArray[0]." which has id: ".$ref." which is in the the menu titled: ".$holdingArray[1];
            $body   .= "\n\rPlease note that sometimes the site isn't able to tell us accurately which menu item was clicked so this may prove to be wrong!";
            $mailer->setSubject('404 Error Generated by '.$siteName.' website');
            $mailer->setBody($body);

            //send mail
            $send = $mailer->Send();

            //Finally redirect to error page
            header("Location: http://www.yourdomain.com/404-page.html"); /* Redirect browser */
            exit();?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM