0

Hello,

I have these codes:

controllers/admin/site.php

<?php

class Site extends CI_Controller
{
    function index()
    {
        $data = array();

        $records = $this->site_model->get_records();
        if (count($records) > 0)
        {
            $data['records'] = $query;
        }

        $this->load->view('admin/options_view', $data);
    }

    function create()
    {
        $data = array(
            'title' => $this->input->post('title'),
            'content' => $this->input->post('content')
        );

        $this->site_model->add_record($data);
        if (true) $this->index(); //added check if something returned from model
    }
}

?>

models/Site_model.php

<?php

class Site_model extends CI_Model {

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

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

    function update_record($data)
    {
        $this->db->where('id', 14);
        $this->db->update('data', $data);
    }

    function delete_row()
    {
        $this->db->where('id', $this->uri->segment(3));
        $this->db->delete('data');
    }

}

?>

views/admin/options_view.php

<!DOCTYPE html>

<html lang="en">
<head>
    <title>untitle</title>
    <style type="text/css" media="screen">
        label {display: block;}
    </style>
</head>
<body>
    <h2>Create</h2>
    <?php echo form_open('site/create');?> 

    <p>
         <label for="title">Title:</label>
         <input type="text" name="title" id="title">
    </p>

    <p>
         <label for="content">Content:</label>
         <input type="text" name="content" id="content">
    </p>

    <p>
         <input type="submit" value="Submit">
    </p>

    <?php echo form_close(); ?>

    <hr>

    <h2>Read</h2>
    <?php if(isset($records)) : foreach($records as $row) : ?>

    <h2><?php echo $row->title; ?></h2>
    <div><?php echo $row->content; ?></div>

    <?php endforeach; ?>

    <?php else : ?>  
    <h2>No records were returned</h2> 
    <?php endif ; ?>




</body>
</html>

After I input the title and content and press submit, it starts to bring me to this url:

http://localhost/IndonusaCI/index.php/admin/site

(it shows the first page and nothing happens)

Instead of saving the data and display it on Read.

2
Contributors
1
Reply
16
Views
3 Years
Discussion Span
Last Post by Tpojka
0
$records = $this->Site_model->get_records();//Capital
  1. Try without using PHP shorthands in view,
  2. Post autoload.php file
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.