EllisLab text mark
Advanced Search
     
Page not found error in create a news tutorial
Posted: 31 January 2012 07:33 AM   [ Ignore ]
Joined: 2012-01-24
4 posts

Hi i am new codeigniter i was just used the given tutorial and there is showing page not found error how can i solve it. help me.

 
Posted: 31 January 2012 08:53 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

Gee let me find my Crytal Ball!

Show some errors and code…

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 01 February 2012 01:54 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-01-24
4 posts

Hi All, Here i am using user guide tutorial for Create news items, i have go through as define in user guide but when we input some data into form and submit, the url will show in the browser ‘http://localhost/generater/index.php/news/localhost/?news/create’ and 404 error will get. and the code process will given here see and help me.

1- Create the new view at application/views/news/create.php.

Create a news item

<?php echo validation_errors(); ?>

<?php echo form_open(‘news/create’) ?>

<label for=“title”>Title</label>
<input type=“input” name=“title” /><br >

<label for=“text”>Text</label>
<textarea name=“text”></textarea>


<input type=“submit” name=“submit” value=“Create news item” />

</form> 

2- News Controler class
class News extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model(‘news_model’);
}

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’);
  // $this->form_validation->run();
 
  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’);
  }
}

}
3- Model class
class News_model extends CI_Model {

public function __construct()
{
  $this->load->database();
}
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);
}
 
}
4- changes in routes.php

$route[‘news/create’] = ‘news/create’;
$route[‘news/(:any)’] = ‘news/view/$1’;
$route[‘news’] = ‘news’;
$route[’(:any)’] = ‘pages/view/$1’;
$route[‘default_controller’] = ‘pages/view’;

Any one help me.

 
Posted: 01 February 2012 02:31 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts
// there should be no ? mark in the url!
http://localhost/generater/index.php/news/localhost/?news/create

// should be this.
http://localhost/generater/index.php/news/localhost/news/create 

Unless it is a typo!

And I do not see your posted page controller.

 

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 11 March 2012 01:13 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-03-08
2 posts

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>
<input type=“input” name=“title” /><br >
<label for=“text”>Text</label>
  <textarea name=“text”></textarea>

<input type=“submit” name=“submit” value=“Create news item” />
    </form>

news.php =
  <?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’);
  }

  }
  ?>

success.php =
  <?php
    echo “Success, new article loaded”;
  ?>

news_model.php =
  <?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.

 
Posted: 11 March 2012 01:29 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

Check your ./application/config/config.php base_url setting.

If you leave it blank CI will figure it out for you.

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 11 March 2012 04:38 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-03-08
2 posts

Aaah, ok, InsiteFX. Thanx for that, that works ! cheers

 
Posted: 15 March 2012 09:08 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2012-03-15
5 posts

Hi,

The tutorial example also not work for me. When I create a news, and submit. It will not go to success page.

Instead it will direct to a weird url: http://www.abc.com/index.php/news/www.abc.com/index.php/news/create

Where, Suppose my base url is http://www.abc.com

Why this happend? I just followed the tutorial exactly. The only thing I added it a success.php page to views/news/

Thanks

 
Posted: 15 March 2012 09:57 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

Show your config.php base_url

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 15 March 2012 10:32 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2012-03-15
5 posts

Before I just left it blank, and it wont work

and I then set it to be


$config[‘base_url’] = ‘www.abc.com’;

still can not work

 
Posted: 15 March 2012 10:54 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

Try setting it like this

$config['base_url''http://www.abc.com/'

 

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 16 March 2012 03:42 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2012-03-16
2 posts

i am here to learn from you.

 
Posted: 16 March 2012 10:16 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2012-03-15
5 posts
InsiteFX - 15 March 2012 10:54 PM

Try setting it like this

$config['base_url''http://www.abc.com/'


It works!! Looks like I need to follow the rule strictly, THanks InsiteFX !!

 
Posted: 03 May 2012 02:09 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2012-05-03
1 posts
InsiteFX - 15 March 2012 10:54 PM

Try setting it like this

$config['base_url''http://www.abc.com/'

This worked for my install as well, you still need to use protocol even for local environments.

Seemed easy enough, compared to Zend’s tutorial, this is a cake walk in no more than 7 functions if fact.  The only thing I’m skeptical about is the routing and how Google likes the way Codeigniter handles permalinks.

 
Posted: 31 October 2012 08:30 PM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2012-10-31
1 posts

For beginners like me, who are using WAMP and are receiving the same error as that on the top where the url seems to be concatenated or doubled after clicking submit, the error was because of the base url being set by you, which was instructed in the tutorial as a must.

I also solved this problem thanks to the solution shown by InsiteFX there, to just leave the base url in the application\config\config.php as blank.