[eluser]zee[/eluser]
Hi
I am new to CI and MVC and was just developing a sample application to learn the things. I was aiming to design a simple website with static pages with title and content being stored in database for each file.
I am using a Pagemodel model as follows
Code:
class Pagemodel extends CI_Model{
function __construct(){
parent::__construct();
}
function fetchDb(){
$data=array();
$this->load->database();
$this->db->select('pagetitle,pagetype,pagecontent');
$this->db->from('pages');
$this->db->where('idpages',1);
$this->db->where('pagestatus',1);
$q=$this->db->get();
if($q->num_rows()>0){
$data=$q->row_array();
}
return $data;
$q->free_result();
}
}
I have made separate controllers for all my pages.
Code:
class Home extends CI_Controller{
function index(){
$this->load->helper('html');
$this->load->helper('url');
$this->load->model('Pagemodel','',TRUE);
$pagedata['content']=$this->Pagemodel->fetchDb();
$this->load->view('sampleview',$pagedata);
}
}
My main aim was to utilize same view (here ‘sampleview’) to generate all pages. As far as I understood MVC approach in CI, I perceived that different controllers need to be called for different pages that fetch data from appropriate model and render it on a view.
Now in case I need to add some PHP generated content, say, a CI form on one of the pages how is it possible? Something like:
Code:
echo form_open('search');
echo form_input();
echo form_submit('submit','search');
echo form_close();
I was trying to find any way if I could make a function for that in model or modify the controller else I would need to make separate views for all pages. Can I pass this code by an array to the view?
Apologies if I sound like an alien!