Forum

Thread tagged as: Problem, Runway

php includes break using PerchSystem::use_error_page(404) in Runway 3

The 404 error page template (perch/templates/pages/errors/404.php) works fine with standard php includes on normal 404s, but nothing is output when called by PerchSystem::use_error_page(404) - I'm trying to output the 404 page when there is no match for the slug on one of the Runway routes.

This is the 404.php:

include($_SERVER['DOCUMENT_ROOT'].'/inc/header.inc.php'); 
perch_content('Error description'); 
include($_SERVER['DOCUMENT_ROOT'].'/inc/footer.inc.php'); 

Any idea how to get included file to work here? Many thanks in advance.

Summary information

Perch Runway: 3.0.4, PHP: 5.6.28, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.0.4), assets (3.0.4), categories (3.0.4), perch_blog (5.5.1), perch_forms (1.9)
App runtimes: <?php $apps_list = [ 'perch_blog', 'perch_forms', ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/adam/Sites/hiddenireland.com/site/perch
PERCH_CORE: /Users/adam/Sites/hiddenireland.com/site/perch/core
PERCH_RESFILEPATH: /Users/adam/Sites/hiddenireland.com/site/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: hiddenireland.dev
DOCUMENT_ROOT: /Users/adam/Sites/hiddenireland.com/site
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Adam Green

Adam Green 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Where are you calling PerchSystem::use_error_page(404) ?

$array = perch_collection($collection, [
    'template' =>'_member.html',
    'filter' => 'memberslug',
    'match' => 'eq',
    'value' => perch_get('memberslug'),
    'count' => 1,
    'skip-template' => true,
]);

if (empty($array)) {
    PerchSystem::use_error_page(404);   
    exit;
}
Drew McLellan

Drew McLellan 2638 points
Perch Support

Why the exit ?

The code above is inside an if statement, so if I remove the exit statement, other content & php includes are output below. It runs at the top of every page template to process meta content; if no memberslug items are matched, there's no need to process meta content - I just want to output the 404 page, but the 404 page content only renders if I remove the php includes from the 404 page template.

Here's a bit more context - this is process-meta.php, included at the top of each page template:

<?php 
// GET META CONTENT FOR DIFFERENT PAGE TYPES
// ====================================================================

if (isset(perch_get('memberslug'))) {

// MEMBER PAGE
// ====================================================================
    $arr_seo = perch_collection('Houses', [
        'template' =>'_house_seo.html',
        'filter' => 'memberslug',
        'match' => 'eq',
        'value' => perch_get('memberslug'),
        'count' => 1,
        'skip-template' => true,
    ]);

    if (empty($arr_seo)) {
        PerchSystem::use_error_page(404);   
        exit;
    }

    $title = $arr_seo[0]['pagetitle'];
    $description = $arr_seo[0]['intro'];

} elseif (isset(perch_get('catfilter'))) {

// LISTING / CATEGORY FILTER PAGE 
// ====================================================================
    $cat_filter = perch_categories(array(
        'skip-template' => true,
        'filter'=> 'catSlug', 
        'match' => 'eq', 
        'value' => perch_get('catfilter'),
    )); 

    $title = $cat_filter[0]['catTitle'];
    $description = $cat_filter[0]['desc'];

} else {

// DEFAULT PAGE
// ====================================================================
    $title = perch_pages_title(true); // default title from pages
    $description = perch_page_attribute('description', array('skip-template'=>true));
}

// Set these variables for use in the attribute templates (Meta tags, OG tags, etc)
PerchSystem::set_vars(array(
    'title'=>$title,
    'description'=>$description,
));
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

With the exit statement, everything stops. That includes generating a 404.

I think you just need to rethink your page logic.

Thanks Drew, all working now after restructuring includes and clearing up the logic - hidden includes within includes!