• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't find thread that talked about calling a second controller

#11
I'm not sure if there will be any problems with what I did, but I tested 404s, DB errors, 503s:


PHP Code:
public function show_error($heading$message$template 'error_general'$status_code 500)
{
    
$templates_path config_item('error_views_path');
    if (empty(
$templates_path))
    {
        
$templates_path VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
    }

    if (
is_cli())
    {
        
$message "\t".(is_array($message) ? implode("\n\t"$message) : $message);
        
$template 'cli'.DIRECTORY_SEPARATOR.$template;
    }
    else
    {
        
set_status_header($status_code);
        
$message '<p>'.(is_array($message) ? implode('</p><p>'$message) : $message).'</p>';
        
$template 'html'.DIRECTORY_SEPARATOR.$template;
    }

    if (
ob_get_level() > $this->ob_level 1)
    {
        
ob_end_flush();
    }
    
ob_start();

    if (
is_cli())
    {
        include(
$templates_path.$template.'.php');
    }
    else
    {
        
$CI =& get_instance();

        
// CI super object not available in some cases
        
if( $CI === NULL )
        {
         
   new CI_Controller();
         
   $CI =& get_instance();
        } 

        
$view_data = [
            
'heading' => $heading,
            
'message' => $message
        
];

        
$data = [
            
'title' => WEBSITE_NAME ' - ' $heading,
            
'remove_top_bar_menu' => 1,
            
'content' => $CI->load->view'errors/' $template$view_dataTRUE )
        ];

        echo 
$CI->load->view'templates/main_template'$dataTRUE );
    }

    
$buffer ob_get_contents();
    
ob_end_clean();
    return 
$buffer;

Reply

#12
(06-09-2016, 11:47 AM)skunkbad Wrote: Actually, what I ended up doing is just extending CI_Exceptions. I fiddled with the proposed MY_Loader, and had a bunch of problems.

That sounds like a much cleaner approach to solve your problem.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.