[eluser]Unknown[/eluser]
I try to fix the problem but I cant any one who help me......
the code in the model class is
?php class Post extends CI_Model{
function get_posts($num=20,$start=0){
$this->db->select()->from('posts')->where('active',1)->order_by('date_added','desc')->limit($num,$start);
$query= $this->db->get();
return $query->result_array();
// $this->db->join('users','users.userID=posts.userID','left');
}
function get_post($postID){
$this->db->select()->from('posts')->where(array('active'=>1,'postID'=>$postID))->order_by('date_added','desc');
$query= $this->db->get();
return $query->first_row('array');
}
function insert_post($data){
/* $data=array(
'title'=>'this is a test',
'description'=>'this is the description'
);*/
$this->db->insert('posts',$data);
return $this->db->insert_id();
}
function update_post($postID,$data){
$this->db->where('postID',$postID);
$this->db->update('posts',$data);
}
function delete_post($postID,$data){
$this->db->where('postID',$postID);
$this->db->delete('posts',$data);
}
function query(){
$this->db->query("SELECT * FROM posts WHERE active=1 ORDER BY date_added desc LIMITS $num,$start");
}
}
and the code in the controller class is
?php
class Posts extends CI_Controller{
function __construct() {
parent::__construct();
$this->load->model('post');
}
function index(){
//$this->load->model('post');
$data['posts'] = $this->post->get_posts();
//echo "<pre>"; print_r($data['posts']);echo "</pre>";
$this->load->view('post_index',$data);
}
function post($postID = NULL){
$data['post']= $this->post->get_post($postID);
// echo "<pre>"; print_r($data['post']);echo "</pre>";
$this->load->view('post',$data);
}
function new_post(){
if($_POST){
$data=array(
'title'=>$_POST['title'],
'post'=>$_POST['post'],
'active'=>1
);
$this->post->insert_post($data);
redirect(base_url().'post/');
} else {
$this->load->view('new_post');
}
}
function editpost($postID){
$data['success']=0;
if($_POST){
$data_post=array(
'title'=>$_POST['title'],
'post'=>$_POST['post'],
'active'=>1
);
$this->post->update_post($postID,$data);
$data['success']=1;
}
$data['post']= $this->post->get_post($postID);
$this->load->view('edit_post',$data);
}
function deletepost($postID){
$this->post->delete_post($postID);
redirect(base_url().'posts');
}
}
and my view is
[code] body>
<div id="wrapper">
<h1> Walaloo </h1>
<div id="container">
<?php if(!isset($post)){ ?>
<p>this page was accessed incorrectly.</p>
<? } else { ?>
<h2><?=$post['title']?></h2>
<?=$post['post']?>
<?php } ?>
</div>
</body>
the error was
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Posts::post()
Filename: controllers/posts.php
Line Number: 15
and
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: postID
Filename: controllers/posts.php
Line Number: 16
how can I fix these problems. thank you