Welcome Guest, Not a member yet? Register   Sign In
Help Printing Messages in View
#1

[eluser]TerryT[/eluser]
Trying to print out messages in my view from the below function. This is from the Ion Auth library. Can anyone tell me what I have to put in my view to echo out the messages. I have tried numerous variations, but still can't get it to work. Thanks.

Terry

Code:
public function messages()
    {
        $_output = '';
        foreach ($this->messages as $message)
        {
            $_output .= $this->message_start_delimiter . $this->ci->lang->line($message) . $this->message_end_delimiter;
        }

        return $_output;
    }
#2

[eluser]InsiteFX[/eluser]
echo $_output;

InsiteFX
#3

[eluser]TerryT[/eluser]
I had tried putting <?php echo $_output; ?> in my view, but I get an undefined variable: _output error. Wasn't able to get rid of the undefined variable so figured I was going down the wrong path.

Terry
#4

[eluser]techgnome[/eluser]
It's a function, returning data... so from some where you're calling that function... you need to put the results of that function into a variable, then pass that to the view some how... how are you calling the function and from where?

-tg
#5

[eluser]InsiteFX[/eluser]
Try this in your controller.
Code:
$data['messages'] = messages();
$this->load_vars($data);
$this->load_view('your_view');

InsiteFX
#6

[eluser]TerryT[/eluser]
Thanks for the help so far. The controller code works. However, I can't get the message to print in my view. Have this in my controller:
Code:
$data2['messages'] = $this->ion_auth->messages();
$this->load->vars($data2);
$this->load->view('users_view');

When I print_r($data2), I get the right messages. In my view I have tried:
Code:
<?php echo $messages; ?>
<?php echo $this->messages; ?>
<?php echo $data2; ?>
<?php echo $data2->messages; ?>
<?php echo $this->data2['messages']; ?>

Everything errors out with undefined variables or trying to do something with a non-object.
#7

[eluser]InsiteFX[/eluser]
How are you loading the Ion_Auth library?

InsiteFX
#8

[eluser]TerryT[/eluser]
Loading it in the controller that I am calling the view from:

Code:
function Users()
        {
            //Load controller parent:
            parent::Controller();
        
            $this->load->library('form_validation');
            $this->load->library('Ion_auth');
            $this->load->model('Users_model');

        }

Terry
#9

[eluser]InsiteFX[/eluser]
Well it looks like something is not setup right to use Ion Auth.

Code:
// this is wrong!
$this->load->library('Ion_auth');

// should be this
$this->load->library('ion_auth');

InsiteFX
#10

[eluser]TerryT[/eluser]
Got it to work using flashdata and sessions:

Controller Code:
Code:
$this->ion_auth->update_user($id, $data1);
            $msgs = $this->ion_auth->messages();
            $this->session->set_flashdata('message', $msgs);

View Code:
Code:
<?php echo $this->session->flashdata('message'); ?>

I can't figure out why I can't access a variable in the view using this code:

Code:
$data2['messages'] = $this->ion_auth->messages();
    $this->load->vars($data2);

Terry




Theme © iAndrew 2016 - Forum software by © MyBB