• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't load views

#1
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
Reply

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

#3
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.
Reply

#4
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.
Reply

#5
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();
 
?>
Reply

#6
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.
Reply

#7
He's true
NexoPOS 2.6.2 available on CodeCanyon.
Reply

#8
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.
NexoPOS 2.6.2 available on CodeCanyon.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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