Welcome Guest, Not a member yet? Register   Sign In
Controller is not passing data to a view. Any Ideas?
#1

[eluser]Zack Kitzmiller[/eluser]
I am having the same issue as the poster, and I can't seem to resolve it.
I can echo out the data in the $data variable in the controller, but it is not getting passed into the view.

My Controller:
Code:
function retrieve_customer()
    {
        $this->auth->restrict();
        
        $data = NULL;
        $message = NULL;
        
        if($this->input->post('retrieve_customer'))
        {
            $this->load->model('dashboard/customer');
            $data = $this->customer->retrieve_customer();
            
            if($data) {
                $this->load->view('dashboard/edit_customer', $data);
            } else {
                $message = "Customer Not Found";
                $this->load->view('dashboard/retrieve_customer', $message);
            }
            
        } else {
            $this->load->view('dashboard/retrieve_customer', $data);
        }
    }

and my edit_customer view:

Code:
</head>

<body>
<?php
echo $data;

?></body>

And my model:

Code:
function retrieve_customer()
    {
        $phone_number = $this->input->post('phone_number');
        
        $this->db->select('*')->from('customers')->where('phone_number', $phone_number)->limit(1);
        $query = $this->db->get();
        
        if($query->num_rows() > 0)
        {
            return $query->row_array();
        } else {
            return NULL;
        }
        
    }

This is driving me crazy, and I'm sure it's something I'm just overlooking. Thanks.
#2

[eluser]jalalski[/eluser]
You don't use the $data variable directly, you use what it contains. e.g.

$data['name'] = 'John';
$data['age'] = 42;

and in the view:

echo $name;
echo $age;
#3

[eluser]breizik[/eluser]
Hi,

$data should be an array, have a look in the user guide http://ellislab.com/codeigniter/user-gui...views.html , paragraph "Adding Dynamic Data to the View"

the example is
Code:
$data = array(
               'title' => 'My Title',
               'heading' => 'My Heading',
               'message' => 'My Message'
          );

$this->load->view('blogview', $data);

and it's passing three variables to the view: $title, $heading and $message
#4

[eluser]Zack Kitzmiller[/eluser]
Thanks, I'm just an idiot.

Smile




Theme © iAndrew 2016 - Forum software by © MyBB