2014-09-17 6 views
0

누락 된 URL에 대한 오류 페이지 (404 페이지)를 만들었습니다. 그것은 표준 방식이나 템플릿의 error.php 파일에서 수행됩니다.joomla 2.5 오류 페이지

오류 페이지가 제대로 작동, 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('[email protected]'); 

      $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에

감사

앨런

+0

[이 스레드] (http://forum.joomla.org/viewtopic.php?f=621&t=685323&view=next)는 Joomla 1.5에서 유용하지만 도움이된다면 약간 변형 할 수 있습니다. 사용되지 않습니다. – DavidT

답변

0

덕분에 그는 올바른 방향으로 절 지적했다. 내가 녹음 해 놨어! 내가 줌라 2.5 다른 사람이 건물 오류 페이지를 도움이됩니다 그렇게 잘하면 코드에 대한 몇 가지 의견을 추가 한 데이비드 T에

다시 한번 감사

앨런 (3.0 그것을 시도하지 않은)

  <?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('[email protected]'); 

      $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();?>