我的問題是我無法讀取單個頁面上的一段數據。例如,在頭版上,我從db中引入了一些笑話;我希望能夠點擊一個笑話並將用戶發送到諸如jokes.com/read/a-chicken-crossed-the-road之類的網址。目前,它發送給我的自定義404頁面的網址是jokes.com/read/1(1是joke_id),我一直無法解決這個問題,所以儘管我會試試這裏。閱讀頁面上的特定帖子
這裏是我的設置:
主要觀點:
<a href="<?php base_url()?>read/<?php echo $joke_id ?>"> <p class="joke-content"><?php echo $joke; ?></p></a>
只讀視圖:
<?php
foreach($results as $row){
echo "<li>$row->joke</li>";
echo "<li>$row->name</li>";
echo "<li>$row->date_added</li>";
}
?>
控制器:
//constructor class enables a function called to be used in any function within this controller
function __construct(){
// Call the Controller constructor
parent::__construct();
$this->load->model('getjokes_m');
}
public function index(){
$this->read();
}
//main jokes functions grabs all the jokes in the database and orders them in their correct category
public function read(){
$data['results'] = $this->getjokes_m->readJokes($this->uri->segment(3));
$this->load->view('template/header');
$this->load->view('template/sidebar');
$this->load->view('content/read', $data);
$this->load->view('template/footer');
}
,最後我的模型:
條function readJokes()
{
$query = $this->db->query('SELECT j.*, c.name FROM jokes j LEFT JOIN category c ON c.category_id = j.category_id WHERE joke_id = ?');
//displays the results if the table has data inside
return $query->result();
}
路線:
$route['default_controller'] = "top";
$route['404_override'] = 'not_found';
$route['register'] = 'login/register';
$route['logout'] = 'login/logout';
$route['admin'] = 'admin/login';
$route['noaccess'] = 'login/noaccess';
我想可能是我使用的SQL語句,因爲它不返回任何數據。
如果有人能指出我正確的方向,爲什麼這不起作用,並獲得URL中的前55個字符,這將是輝煌的。
您的「視圖」甚至沒有鏈接... –
數據的鏈接位於主控制器中,我已將其編輯爲現在顯示 – steviem1986
它應該是href ='<?回聲base_url() – aseferov