Welcome Guest, Not a member yet? Register   Sign In
Problem with CI Tutorial
#1

[eluser]chubbypama[/eluser]
Hi there. I'm just making my way through the CI tutorials that are included as a part of the documentation.
I have created the controller called "news". And in it, I've created both the "create" and "set_news" methods. (please see code below). However, when I test the app and try to save a news item, I get the following error message:

Quote:( ! ) Fatal error: Call to undefined method News_model:Confusedet_news() in C:\wamp\www\CodeIgniter\application\controllers\news.php on line 52
Call Stack
# Time Memory Function Location
1 0.0015 388976 {main}( ) ..\index.php:0
2 0.0055 462008 require_once( 'C:\wamp\www\CodeIgniter\system\core\CodeIgniter.php' ) ..\index.php:202
3 0.0865 2585168 call_user_func_array ( ) ..\CodeIgniter.php:359
4 0.0865 2585216 News->create( ) ..\CodeIgniter.php:359


Source code in news.php looks like this:
Code:
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 is executed on submit and when validation rules fails
   {
    echo('validating form');
    $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');
   }
  }
  
  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);
  }
#2

[eluser]chubbypama[/eluser]
doh!
i figured it out. the set_news should be in my model, not controller.
sorry.




Theme © iAndrew 2016 - Forum software by © MyBB