CodeIgniter Forums
Can't load views - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Can't load views (/showthread.php?tid=62128)



Can't load views - tomop - 06-12-2015

Hi guys, I have this edit_profile function in my site controller and I want logged-in person to edit just their profile (I am storing their ID in session data and comparing them with segment(3)). If IDs match, they can view and edit their profile, if not, they get an error message. My problem is that the error message is not loading header and footer views although I see the error message. I have 3 modules (Login, Site, Home) but my header and footer view are stored in an application/view folder.

PHP Code:
   function edit_profile() {

 
   $right_user $this->right_user();

 
   if ($right_user == true)
    {
     
   $this->load->view('includes/header');
     
   $this->load->model('login/membership_model');
     
   $user $this->membership_model->get_member_details($this->uri->segment(3));
     
   $this->load->view('edit_profile'$user);
 
   }

 
   else
    
{
        
$this->load->view('includes/header');
        echo 
'Nemáte povolení prohlížet tuto stránku. <p>';
        echo 
anchor('login''Login');
        echo 
'<p>';
        echo 
anchor('home''Home');
        
$this->load->view('includes/footer');
 
       die();
 
   }
    } 

I have similar function is_logged_in in my login controller and that one works fine.

PHP Code:
    function is_logged_in()
    {
        
$is_logged_in $this->session->userdata('is_logged_in');
        if(!isset(
$is_logged_in) || $is_logged_in != true)
        {
            
$this->load->view('includes/header');
            echo 
'Nemáte povolení prohlížet tuto stránku. <p>';
            echo 
anchor('login''Login');
            echo 
'<p>';
            echo 
anchor('home''Home');
            
$this->load->view('includes/footer');

            die();        
        }        
    } 

Any ideas? Cool


RE: Can't load views - Avenirer - 06-12-2015

Why would you echo something inside a controller and not inside the view?


RE: Can't load views - CroNiX - 06-12-2015

You can't echo from controllers. For testing things that's fine, but when you echo from a controller, whatever you echo will show up BEFORE and of your views get output because you are bypassing CI's buffered output.


RE: Can't load views - gadelat - 06-12-2015

Non of those can work. If you terminate execution of PHP script in your controller (via die() etc.), your views won't be outputted, because their content is normally outputted only after controller properly ended. Display your error messages via own view, or pass these messages to other view as data.


RE: Can't load views - tomop - 06-12-2015

Thank you for your reactions, I'm new to this all MVC/HMVC stuff so I guess it is driving you crazy when you see what I've written  Smile .

Is this a better way then?

Edit_profile function inside controller:

PHP Code:
   function edit_profile() {

 
   $right_user $this->right_user();

 
   if ($right_user == true)
        {
            
$this->load->view('includes/header');
     
       $this->load->model('login/membership_model');
     
       $user $this->membership_model->get_member_details($this->uri->segment(3));
            
$this->load->view('edit_profile'$user);
 
       }

 
   else
        
{
            
$this->load->view('includes/no_permission');
 
       }
    } 

No_permission view:

PHP Code:
<?php     $this->load->view('includes/header');

        echo 
'Nemáte povolení prohlížet tuto stránku. <p>';
        echo 
anchor('login''Login');
        echo 
'<p>';
        echo 
anchor('home''Home');


        
$this->load->view('includes/footer');
        die();
 
?>



RE: Can't load views - CroNiX - 06-12-2015

get rid of the die() in the no_permission view. You are preventing the rest of CI from running, which outputs your views after the controller finishes running.


RE: Can't load views - Blair2004 - 06-13-2015

He's true


RE: Can't load views - Blair2004 - 06-13-2015

You should no use die within a view file... you can redirect use if you want to prevent something important to be displayed and send use to specific error page.