Welcome Guest, Not a member yet? Register   Sign In
Calling controller

i have created my controller like this

class News extends CI_Controller {

public function __construct()// constuctor
  $this->load->model('news_model');// load news_model at startup

public function index($page = 'index')
  $data['news'] = $this->news_model->get_news();// function writen in model
  $this->load->view('templates/header', $data);
  $this->load->view('news/index', $data);
  $this->load->view('templates/footer', $data);

public function create()
  $this->load->helper('form');// helper library default of codeigniter
  $this->load->library('form_validation');// helper library default of codeigniter

  $data['title'] = 'Create a news item';

  $this->form_validation->set_rules('title', 'Title', 'required');// we have to set criteria of each form elemen, it will evaluate automaticallly
  $this->form_validation->set_rules('text', 'text', 'required');

  if ($this->form_validation->run() === FALSE)// if valiadtion false then return error message
   $this->load->view('templates/header', $data);
   $this->load->view('news/success');// success message will be shown

public function set_news()

  $data = array(
   'title' => $this->input->post('title'),
   'text' => $this->input->post('text')

  return $this->db->insert('news', $data);// data will be inserted to database

and i want to call this create method from a view how should i do that. I have no idea to do that pls help me

Do you mean passing data from controller to view?

Theme © iAndrew 2016 - Forum software by © MyBB