Welcome Guest, Not a member yet? Register   Sign In
Page not found error in create a news tutorial
#5

[eluser]greggie[/eluser]
Hi, I have the same 404 error problem after clicking the create news item button -instead of the success page, or the form again. The URL doubles up from -"http://localhost/CI_2.1.0/index.php/news/create" to "http://localhost/CI_2.1.0/index.php/news/localhost/index.php/news/create".

All my code for the pages are as follows, as I worked through the tutorial.
(I would note that working through the tutorials is difficult, as there seems to be the odd code error-based on the forum input- and a bit vague as to which page the next code snippet should go to! Perhaps being able to down load the working files at the end of each tut would aid us newbies, and reduce your work load!).

create.php =
<?php echo validation_errors(); ?>
<?php echo form_open('news/create') ?>
<label for="title">Title</label>
&lt;input type="input" name="title" /&gt;&lt;br />
<label for="text">Text</label>
&lt;textarea name="text"&gt;&lt;/textarea><br />
&lt;input type="submit" name="submit" value="Create news item" /&gt;
&lt;/form&gt;

news.php =
&lt;?php
class News extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}

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');
}

public function view($slug)
{
$data['news_item'] = $this->news_model->get_news($slug);
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];

$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}

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');
}
}
}
?&gt;

success.php =
&lt;?php
echo "Success, new article loaded";
?&gt;

news_model.php =
&lt;?php
class News_model extends CI_Model
{
public function __construct()
{
$this->load->database();
}

public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
}

$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}

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);
}
}

routes.php =
$route['news/(:any)'] = 'news/view/$1'; // used for a dynamic tut
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

/* An extra rule to start adding news items. This makes sure CodeIgniter sees'create' as a method instead of a news item's slug. */
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

I can't see where the problem is. Needless to say, nothing is getting written to the Db.
Any help is much appreciated. Thanx.


Messages In This Thread
Page not found error in create a news tutorial - by El Forum - 01-31-2012, 04:33 AM
Page not found error in create a news tutorial - by El Forum - 01-31-2012, 05:53 AM
Page not found error in create a news tutorial - by El Forum - 01-31-2012, 10:54 PM
Page not found error in create a news tutorial - by El Forum - 01-31-2012, 11:31 PM
Page not found error in create a news tutorial - by El Forum - 03-10-2012, 10:13 PM
Page not found error in create a news tutorial - by El Forum - 03-10-2012, 10:29 PM
Page not found error in create a news tutorial - by El Forum - 03-11-2012, 01:38 AM
Page not found error in create a news tutorial - by El Forum - 03-15-2012, 06:08 PM
Page not found error in create a news tutorial - by El Forum - 03-15-2012, 06:57 PM
Page not found error in create a news tutorial - by El Forum - 03-15-2012, 07:32 PM
Page not found error in create a news tutorial - by El Forum - 03-15-2012, 07:54 PM
Page not found error in create a news tutorial - by El Forum - 03-16-2012, 12:42 AM
Page not found error in create a news tutorial - by El Forum - 03-16-2012, 07:16 AM
Page not found error in create a news tutorial - by El Forum - 05-02-2012, 11:09 PM
Page not found error in create a news tutorial - by El Forum - 10-31-2012, 05:30 PM
Page not found error in create a news tutorial - by El Forum - 12-13-2013, 04:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB