2
votes

Here's the issue : CodeIgniter loads data from the controller but not from the view

When I go the the source of the page and click the form action link its load data in the source code but not in the html view.

--view

<table class="table hovered">
            <thead>
            <tr>
                <th class="text-left">User ID</th>
                <th class="text-left">Type</th>
                <th class="text-left">Name</th>
                <th class="text-left">Email</th>
                <th class="text-left">Phone</th>
            </tr>
            </thead>
            <tbody>
            <?php echo form_open('admin/manage_customer')  ?><!-- start of the form -->
            <?php if(isset($records)) : foreach($records as $row) : ?>
                <tr>
                    <td class="right"><?php echo $row->cus_id; ?></td>
                    <td class="right">Admin</td>
                    <td class="right"><?php echo $row->cus_name; ?></td>
                    <td class="right"><?php echo $row->cus_email; ?></td>
                    <td class="right"><?php echo $row->cus_phone; ?></td>
                </tr>
            <?php endforeach; ?>
            <?php endif; ?>
            <?php echo form_close(); ?><!-- END of the form -->
            </tbody>
            <tfoot></tfoot>
        </table>

---controller

  function inbox()
{
    $data = array();
    if($query = $this->mod_contactus->get_records())
    {
        $data['records'] = $query;
    }
    $this->load->view('admin/admin_messages',$data);
}

---Model

<?php
class Mod_contactus extends CI_Model //Users (model name) share all the class and functions CodeIgniter models have

    {

    function get_records()
    {
        $query = $this->db->get('tbl_contactus');
        return $query->result();
    }


    function add_record($data)
    {
        $this->db->insert('tbl_contactus', $data);
        return;
    }


    function update_record()
    {
    }

}
1
did you try var_dump($records) or print_r($records) in your view? try it. if it's dumping data then it's maybe an html structure issue. - xmaestro
yer i tried var_dump($records) but nothing comes - Walter White
This seems like a duplicate of this question. stackoverflow.com/questions/23531777/… Does the same course of action correct this? - d.lanza38

1 Answers

0
votes

i would go with hussain in this. first check if the necessary data is returned by the model or not. Only then you should check the html structure. But even if there is a problem with structure, something should be displayed. So, check the flow of data to the view first.