We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Custom 404 template broken

Developer Preview

Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
about 14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

It looks like you changed the 404 template query creation from the old manual stringed query route to using CI’s active record. Because of this you’ve got a new bug where you check if the query string is empty as a way of checking if you’re on a 404 page.

In libraries/Template.php:

Line 2006 sets $sql_404 to an empty string Lines 2040 and 2070 add a where clause to the active record instance (each line does it based on different conditions) Line 2083 checks if $sql_404 is still an empty string to see if you’re dealing with a 404

Since $sql_404 is never altered it is always an empty string and thus the 404 page isn’t being pulled from the database.

Since the conditional around $sql_404 is an exact comparison I just added the following code to lines 2044 and 2075:

$sql_404 = TRUE;

I imagine you’ll have a different solution / fix but this at least gives me my 404 back 😊

Thanks, Erik

       
Wes Baker's avatar
Wes Baker
343 posts
about 14 years ago
Wes Baker's avatar Wes Baker

Erik, that solution sounds good to me. The only change I made was renaming the variable to $show_404.

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
about 14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
The only change I made was renaming the variable to $show_404.

Good call.

Thanks, Wes.

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
about 14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Well, if you’re going that route, why not just start off with $show_404 = FALSE and change the conditional as well?

       
Wes Baker's avatar
Wes Baker
343 posts
about 14 years ago
Wes Baker's avatar Wes Baker

That’s exactly what I did 😊

public function fetch_template($template_group, $template, $show_default = TRUE, $site_id = '')
{
 if ($site_id == '' OR ! is_numeric($site_id))
 {
  $site_id = $this->EE->config->item('site_id');
 }
 
 $this->log_item("Retrieving Template from Database: ".$template_group.'/'.$template);
  
 $show_404 = FALSE;
 $template_group_404 = '';
 $template_404 = '';
 
 /* -------------------------------------------
 /* Hidden Configuration Variable
 /* - hidden_template_indicator => '.' 
  The character(s) used to designate a template as "hidden"
 /* -------------------------------------------*/

 $hidden_indicator = ($this->EE->config->item('hidden_template_indicator') === FALSE) ? '.' : $this->EE->config->item('hidden_template_indicator');   
 
 if ($this->depth == 0 AND substr($template, 0, 1) == $hidden_indicator)
 {
  /* -------------------------------------------
  /* Hidden Configuration Variable
  /* - hidden_template_404 => y/n 
   If a hidden template is encountered, the default behavior is
   to throw a 404.  With this set to 'n', the template group's
   index page will be shown instead
  /* -------------------------------------------*/
  
  if ($this->EE->config->item('hidden_template_404') !== 'n')
  {
   $x = explode("/", $this->EE->config->item('site_404'));
   
   if (isset($x[0]) AND isset($x[1]))
   {
    $this->EE->output->out_type = '404';
    $this->template_type = '404';
    
    $template_group_404 = $this->EE->db->escape_str($x[0]);
    $template_404 = $this->EE->db->escape_str($x[1]);
    
    $this->EE->db->where(array(
     'template_groups.group_name' => $x[0],
     'templates.template_name'  => $x[1]
    ));

    $show_404 = TRUE;
   }
   else
   {
    $template = 'index';
   }
  }
  else
  {
   $template = 'index';
  }
 }
 
 if ($template_group == '' && $show_default == FALSE && $this->EE->config->item('site_404') != '')
 {
  $treq = $this->EE->config->item('site_404');
  
  $x = explode("/", $treq);
  
  if (isset($x[0]) AND isset($x[1]))
  {
   $this->EE->output->out_type = '404';
   $this->template_type = '404';
   
   $template_group_404 = $this->EE->db->escape_str($x[0]);
   $template_404 = $this->EE->db->escape_str($x[1]);
   
   $this->EE->db->where(array(
    'template_groups.group_name' => $x[0],
    'templates.template_name'  => $x[1]
   ));

   $show_404 = TRUE;
  } 
 }
 
 $this->EE->db->select('templates.*, template_groups.group_name')
  ->from('templates')
  ->join('template_groups', 'template_groups.group_id = templates.group_id')
  ->where('template_groups.site_id', $site_id);
 
 // If we're not dealing with a 404, what template and group do we need?
 if ($show_404 === FALSE)
 {
  // Definitely need a template
  if ($template != '')
  {
   $this->EE->db->where('templates.template_name', $template);
  }
  
  // But do we have a template group?
  if ($show_default == TRUE)
  {
   $this->EE->db->where('template_groups.is_site_default', 'y');
  }
  else
  {
   $this->EE->db->where('template_groups.group_name', $template_group);
  }
 }
       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
about 14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Awesome. Thanks man!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.