public function redirect404(MvcEvent $e, $idpage = null)
    {
    	$sm = $e->getApplication()->getServiceManager();
        $eventManager = $e->getApplication()->getEventManager();
		
    	$melisTree = $sm->get('MelisEngineTree');
		$melisSiteDomain = $sm->get('MelisEngineTableSiteDomain');
		$melisSite404 = $sm->get('MelisEngineTableSite404');
    	
    	if ($idpage == null)
    	{
    		// idPage is not working, we get the site through the domain
    		// used to redirect to the right 404
    		$router = $e->getRouter();
			$uri = $router->getRequestUri();
			$domainTxt = $uri->getHost();
    	}
    	else
    	{
    		// We get the site using the idPage and redirect to the site's 404
    		$domainTxt = $melisTree->getDomainByPageId($idpage, true);
    		if (empty($domainTxt))
    		{
    		    $router = $e->getRouter();
    		    $uri = $router->getRequestUri();
    		    $domainTxt = $uri->getHost();
    		}
    		
    		$domainTxt = str_replace('http://', '', $domainTxt);
    		$domainTxt = str_replace('https://', '', $domainTxt);
    	}

    	// Get the siteId from the domain
    	if ($domainTxt)
    	{
			$domain = $melisSiteDomain->getEntryByField('sdom_domain', $domainTxt);
			
			$domain = $domain->current();
			if ($domain)
    			$siteId = $domain->sdom_site_id;
			else
			    return '';
    	}
    	else
    	    return '';

    	// Get the 404 of the siteId
    	$site404 = $melisSite404->getEntryByField('s404_site_id', $siteId);
    	if ($site404)
    	{
    		$site404 = $site404->current();
    		if (empty($site404))
    		{
    			// No entry in DB for this siteId, let's get the general one (siteId -1)
    			$site404 = $melisSite404->getEntryByField('s404_site_id', -1);
    			$site404 = $site404->current();
    		}
    	}
    	
    	if (empty($site404))
    	{
    		// No 404 found
    		return '';
    	}
    	else
    	{
    		// Check if the 404 defined exist also!
		    $melisPage = $sm->get('MelisEnginePage');
		    $datasPage = $melisPage->getDatasPage($site404->s404_page_id, 'published');
		    $pageTree = $datasPage->getMelisPageTree();
		    
		    if (empty($pageTree))
		        return ''; // The 404 page defined doesn't exist or is not published
    		
    		// Redirect to the 404 of the site
    		$link = $melisTree->getPageLink($site404->s404_page_id, true);
    		
    		return $link;
    	}
    }
public function redirect404(MvcEvent $e, $idpage = null)
    {
    	$sm = $e->getApplication()->getServiceManager();
        $eventManager = $e->getApplication()->getEventManager();
		
    	$melisTree = $sm->get('MelisEngineTree');
		$melisSiteDomain = $sm->get('MelisEngineTableSiteDomain');
		$melisSite404 = $sm->get('MelisEngineTableSite404');
    	
    	if ($idpage == null)
    	{
    		// idPage is not working, we get the site through the domain
    		// used to redirect to the right 404
    		$router = $e->getRouter();
			$uri = $router->getRequestUri();
			$domainTxt = $uri->getHost();
    	}
    	else
    	{
    		// We get the site using the idPage and redirect to the site's 404
    		$domainTxt = $melisTree->getDomainByPageId($idpage, true);
    		if (empty($domainTxt))
    		{
    		    $router = $e->getRouter();
    		    $uri = $router->getRequestUri();
    		    $domainTxt = $uri->getHost();
    		}
    		
    		$domainTxt = str_replace('http://', '', $domainTxt);
    		$domainTxt = str_replace('https://', '', $domainTxt);
    	}

    	// Get the siteId from the domain
    	if ($domainTxt)
    	{
			$domain = $melisSiteDomain->getEntryByField('sdom_domain', $domainTxt);
			
			$domain = $domain->current();
			if ($domain)
    			$siteId = $domain->sdom_site_id;
			else
			    return '';
    	}
    	else
    	    return '';

    	// Get the 404 of the siteId
    	$site404 = $melisSite404->getEntryByField('s404_site_id', $siteId);
    	if ($site404)
    	{
    		$site404 = $site404->current();
    		if (empty($site404))
    		{
    			// No entry in DB for this siteId, let's get the general one (siteId -1)
    			$site404 = $melisSite404->getEntryByField('s404_site_id', -1);
    			$site404 = $site404->current();
    		}
    	}
    	
    	if (empty($site404))
    	{
    		// No 404 found
    		return '';
    	}
    	else
    	{
    		// Check if the 404 defined exist also!
		    $melisPage = $sm->get('MelisEnginePage');
		    $datasPage = $melisPage->getDatasPage($site404->s404_page_id, 'published');
		    $pageTree = $datasPage->getMelisPageTree();
		    
		    if (empty($pageTree))
		        return ''; // The 404 page defined doesn't exist or is not published
    		
    		// Redirect to the 404 of the site
    		$link = $melisTree->getPageLink($site404->s404_page_id, true);
    		
    		return $link;
    	}
    }
public function redirect404 ( MvcEvent $ e , $ idpage = null ) { $ sm = $ e -> getApplication ( ) -> getServiceManager ( ) ; $ eventManager = $ e -> getApplication ( ) -> getEventManager ( ) ; $ melisTree = $ sm -> get ( 'MelisEngineTree' ) ; $ melisSiteDomain = $ sm -> get ( 'MelisEngineTableSiteDomain' ) ; $ melisSite404 = $ sm -> get ( 'MelisEngineTableSite404' ) ; if ( $ idpage == null ) { // idPage is not working, we get the site through the domain // used to redirect to the right 404 $ router = $ e -> getRouter ( ) ; $ uri = $ router -> getRequestUri ( ) ; $ domainTxt = $ uri -> getHost ( ) ; } else { // We get the site using the idPage and redirect to the site's 404 $ domainTxt = $ melisTree -> getDomainByPageId ( $ idpage , true ) ; if ( empty ( $ domainTxt ) ) { $ router = $ e -> getRouter ( ) ; $ uri = $ router -> getRequestUri ( ) ; $ domainTxt = $ uri -> getHost ( ) ; } $ domainTxt = str_replace ( 'http://' , '' , $ domainTxt ) ; $ domainTxt = str_replace ( 'https://' , '' , $ domainTxt ) ; } // Get the siteId from the domain if ( $ domainTxt ) { $ domain = $ melisSiteDomain -> getEntryByField ( 'sdom_domain' , $ domainTxt ) ; $ domain = $ domain -> current ( ) ; if ( $ domain ) $ siteId = $ domain -> sdom_site_id ; else return '' ; } else return '' ; // Get the 404 of the siteId $ site404 = $ melisSite404 -> getEntryByField ( 's404_site_id' , $ siteId ) ; if ( $ site404 ) { $ site404 = $ site404 -> current ( ) ; if ( empty ( $ site404 ) ) { // No entry in DB for this siteId, let's get the general one (siteId -1) $ site404 = $ melisSite404 -> getEntryByField ( 's404_site_id' , - 1 ) ; $ site404 = $ site404 -> current ( ) ; } } if ( empty ( $ site404 ) ) { // No 404 found return '' ; } else { // Check if the 404 defined exist also! $ melisPage = $ sm -> get ( 'MelisEnginePage' ) ; $ datasPage = $ melisPage -> getDatasPage ( $ site404 -> s404_page_id , 'published' ) ; $ pageTree = $ datasPage -> getMelisPageTree ( ) ; if ( empty ( $ pageTree ) ) return '' ; // The 404 page defined doesn't exist or is not published // Redirect to the 404 of the site $ link = $ melisTree -> getPageLink ( $ site404 -> s404_page_id , true ) ; return $ link ; } }
Get the 404 page's URL
404 can occur if page is not found or if page is not published
This function will try to find the 404 defined for the site of this page,
if not the general 404, then an empty string if nothing is defined

@param MvcEvent $e
@param int $idpage The id of the page
Get the 404 page s URL 404 can occur if page is not found or if page is not published This function will try to find the 404 defined for the site of this page if not the general 404 then an empty string if nothing is defined