Thank you for your replies Aken and PhilTem.
I’ve proceeded to the next page of the tutorial. I see the line in the news_model.php for setting $slug. As for it’s purpose, I assumed it was a search field, but perhaps it’s not (there are other ways to access and keep track of a table record) . Perhaps this will become clear later on (perhaps not).
Anyway, the “next page of the tutorial” has introduced a new error for me. When I access the news/create view page, the form is displayed, and I’m able to enter information into the two fields.
OK - never mind. I found the mistake (which of course I introduced). Sorry for the erroneous post.
view/news/create.php:
<h2>Create a news item</h2>
<p><?php echo validation_errors(); ?></p>
<p><?php echo form_open('news/create') ?></p>
<p> <label for="title">Title</label><br />
<input type="input" name="title" /> </p>
<p> <br />
<label for="text">Text</label><br />
<textarea name="text"></textarea> </p>
<p> <br />
<input type="submit" name="submit" value="Create news item" /><br />
<br />
</form>controllers/news.php:
<?php
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
} // end function __construct()
public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';
$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
} // end function index()
public function view($slug)
{
$data['news'] = $this->news_model->get_news($slug);
if (empty($data['news']))
{
show_404();
} // end if
$data['title'] = $data['news']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
} // end function view()
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Create a news item';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('text', 'text', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('news/create');
$this->load->view('templates/footer');
}
else
{
$this->news_model->set_news();
$this->load->view('news/success');
}
} //end function create()
} // end class Newsmodels/news_model.php:
<?php
class News_model extends CI_Model {
public function __construct()
{
$this->load->database();
} //end function __construct()
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
} //end if
$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
} // end function get_news()
public function set_news()
{
$this->load->helper('url');
$slug = url_title($this->input->post('title'), 'dash', TRUE);
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'text' => $this->input->post('text')
);
return $this->db->insert('news', $data);
} // end function set_news()
} // end class News_modelconfig/routes:
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
$route['404_override'] = 'errors/page_missing';
Thank you again for any guidance.