CodeIgniter Forums
Hooks - A foolish problem solved! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Hooks - A foolish problem solved! (/showthread.php?tid=2046)



Hooks - A foolish problem solved! - El Forum - 07-13-2007

[eluser]libnac[/eluser]
Hi,

If anyone has problems with a hooks be sure that the hook class or function is not finished by any blank space or anything else, because you will be in a trouble.

Code:
<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Lang
*/

function setlang() {
    
    $ci =& get_instance();
    
    $class = strtolower($ci->uri->router->class);
  
    
    if(!$ci->db_session->userdata('logged_in')) {
        
        $newdata = array(
                   'username'  => 'guest',
                   'email'     => '',
                   'logged_in' => TRUE,
                   'lang'        => 'spanish',
               );
        
        $ci->db_session->set_userdata($newdata);
    }
    
    $ci->lang->load($class , $ci->db_session->userdata('lang'));
}
?&gt; <-- !!!!!!!!DELETE ALL CHARS FROM HERE!!!!!!!!


I hope this will be useful.

Regards,
libnac


Hooks - A foolish problem solved! - El Forum - 07-13-2007

[eluser]Glen Swinfield[/eluser]
Same applies to any other file - whitespace = content so redirect will not work because headers will already be sent, and a whole load of other issues.


Hooks - A foolish problem solved! - El Forum - 07-25-2007

[eluser]Newton Wagner[/eluser]
In addition, the php end tag (?&gtWink is optional... so you can remove them and you will not have this problem again. Smile.