• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
having trouble with controller , showing not found page

#1
[eluser]Unknown[/eluser]
hi i'm having trouble to make the code work

post controller:
Code:
<?php
class Post extends CI_Controller{
    function __construct() {
        parent::__construct();
        $this->load->model("post_model");
    
}
public function index() {
    $data['posts']=  $this->post_model->get_post();
    $data['title']="Posts";
    $this->load->view("templates/header",$data);
    $this->load->view("post/index",$data);
      $this->load->view("templates/footer",$data);
}
public function view($id){
    $data["postss"]=  $this->post_model->get_post($id);
    if(empty($data["postss"])){
        show_404();
    }
    $data['title']="Post view";
    $this->load->view("templates/header",$data);
    $this->load->view("post/view",$data);
    $this->load->view("templates/footer",$data);
    
}
}
?>

post model:
Code:
<?php
class Post_model extends CI_Model {

    function __construct() {
        $this->load->database();
    }
    public function get_post($id=false){
    
        if ($id === FALSE)
{
  $query = $this->db->get('posts');
  return $query->result_array();
}

$query = $this->db->get_where('posts', array('id' => $id));
return $query->row_array();
    }
    public function set_post() {
        $this->load->helper("url");
        $data=array("title"=>  $this->input->post("title"),"content"=>  $this->input->post("content"));
        $this->db->insert("posts",$data);
    }

}
?>

routes:
Code:
$route['default_controller'] = "pages/view";
$route['404_override'] = '';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';

$route['post'] = 'post';


view method doesn't work can anyone help me ?

#2
[eluser]vitoco[/eluser]
I think that your routing it's the problem
Code:
$route['default_controller'] = "pages/view";
$route['404_override'] = '';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1'; // I THINK THAT THIS ONE CATCH THE REQUEST

$route['post'] = 'post';

so this may work

Code:
$route['default_controller'] = "pages/view";
$route['404_override'] = '';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['post'] = 'post'; // THIS ONE CATCHES POST
$route['(:any)'] = 'pages/view/$1'; // THIS ONE ALL THE REST

Saludos


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.