Welcome Guest, Not a member yet? Register   Sign In
Set Header 404
#1

I am new to out put class.

What I am trying to achieve is if category not found then will go to my custom not found page.

I think it's working but not sure if I have used this correct $this->output->set_status_header('404');


PHP Code:
<?php

class Category extends MX_Controller {

    public function 
index() {

        
$get_path $this->input->get('path');

        if (isset(
$get_path)) {

            
$path '';

            
$parts explode('_', (string)$get_path);

            
$category_id = (int)array_pop($parts);

            foreach (
$parts as $path_id) {
                if (!
$path) {
                    
$path = (int)$path_id;
                } else {
                    
$path .= '_' . (int)$path_id;
                }

                
$category_info $this->get_category($path_id);

                if (
$category_info) {
                    
$data['breadcrumbs'][] = array(
                        
'text' => $category_info['name'],
                        
'href' => site_url('page/category') .'/''?&path=' $path
                    
);
                }
            }

        } else {
        
            
$category_id 0;
        
        }

        
$category_info $this->get_category($category_id);

        if (
$category_info) {

            
$data['text_empty'] = "There are no pages to list in this category.";

            
// Get Categories

            
$data['categories'] = array();

            
// Get Pages

            
$data['pages'] = array();

            
$this->load->view('theme/default/template/page/category'$data);

        } else {

            
$this->output->set_status_header('404');

            
$data['heading_title'] = 'Category not found!';

            
$data['text_error'] = "Category not found!";

            
$this->load->view('theme/default/template/error/not_found'$data);

        }

    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

Hi.

The way you used the set_status_header() is perfectly fine.

Another option is to use helper function show_404() which will automatically load the application/errors/error_404.php or application/views/errors/html/error_404.php template depending on your CodeIgniter version and terminate controller execution.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB