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

[eluser]Unknown[/eluser]
i have created my controller like this
Code:
<?php

class News extends CI_Controller {


public function __construct()// constuctor
{
  parent::__construct();
  $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/create');
   $this->load->view('templates/footer');
  
  }
  else
  {
   $this->news_model->set_news();
   $this->load->view('news/success');// success message will be shown
  }
}

public function set_news()
{
  $this->load->helper('url');


  $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
#2

[eluser]greedyman[/eluser]
Do you mean passing data from controller to view?




Theme © iAndrew 2016 - Forum software by © MyBB