In this page , Iam describing about doing basic functions in codeigniter like listing data, inserting data, deleting data, updating data,uploading images,generating thumbnail of images.etc. If you are doing a simple project website in codeigniter this page will be useful for you.
Listing data
............................
Here iam describing an example of a news adding website. so in that project we will certainly have a page where all data will be listed. For details about where to add controller,model and view refer my previous page:- http://phpdudes.blogspot.in/2012/09/codeigniter-sample-project.html
First you have to write method in controller:-
public function news(){
$this->load->helper('form');
$this->load->helper('url');
$data['urls']=base_url();//basic root url
$data['news'] = $this->news_model->get_news();// retreive newslist from model
$data['count']=count($data['news']);
$this->load->view('templates/headermain',$data);//loading the header
$this->load->view('admin/news',$data);
$this->load->view('templates/footermain');//loading the footer
}
So you have a function named get_news in the news model:-
public function get_news()
{
$query = $this->db->get('news');
return $query->result_array();
}
So in the view page you have to code like this:-
foreach($news as $news_item){
?>
<li>
<input type="hidden" name="id<?php echo $i;?>" value="<?php echo $news_item['news_id'];?>" />
<div class="row250"><?php echo $news_item["title"];?></div>
<?php } ?>
Listing data
............................
Here iam describing an example of a news adding website. so in that project we will certainly have a page where all data will be listed. For details about where to add controller,model and view refer my previous page:- http://phpdudes.blogspot.in/2012/09/codeigniter-sample-project.html
First you have to write method in controller:-
public function news(){
$this->load->helper('form');
$this->load->helper('url');
$data['urls']=base_url();//basic root url
$data['news'] = $this->news_model->get_news();// retreive newslist from model
$data['count']=count($data['news']);
$this->load->view('templates/headermain',$data);//loading the header
$this->load->view('admin/news',$data);
$this->load->view('templates/footermain');//loading the footer
}
So you have a function named get_news in the news model:-
public function get_news()
{
$query = $this->db->get('news');
return $query->result_array();
}
So in the view page you have to code like this:-
foreach($news as $news_item){
?>
<li>
<input type="hidden" name="id<?php echo $i;?>" value="<?php echo $news_item['news_id'];?>" />
<div class="row250"><?php echo $news_item["title"];?></div>
<?php } ?>
No comments:
Post a Comment