如何將兩個不同的功能從同一個控制器輸出到同一視圖(頁面)? 例如,我有一個函數去「文章」股利,另一個功能,我試圖在「旁邊」div內使用。 (在這裏使用HTML 5命名法)2一個視圖上的Codeigniter控制器查詢
我已經儘可能在(視圖)旁邊div中使用實際的數據庫查詢,它仍然只顯示第1條文章函數。
我改變了$ data('result')變量來分隔變量,這沒有什麼區別。
我正在展示我必須在文章div中完成的待辦事項列表,然後在旁邊div中顯示已完成的待辦事項的標題。
我想我正在弄亂這個解釋。你會使用不同控制器的功能嗎?
這是在控制器
function index()
{
$this->load->model('work_m');
$data = array();
$config['base_url'] = base_url() . 'index.php/work/index/';
$config['total_rows'] = $this->db->count_all('work');
$config['per_page'] = '10';
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['result'] = $this->work_m->get_records($config['per_page'], $this->uri->
segment(3));
$tmpl = array('table_open' =>
'<table border="0" cellpadding="0" cellspacing="0">', 'heading_row_start' =>
'<tr class="heading">', 'heading_row_end' => '</tr>', 'heading_cell_start' =>
'<th>', 'heading_cell_end' => '</th>', 'row_start' => '<tr>', 'row_end' =>
'</tr>', 'cell_start' => '<td>', 'cell_end' => '</td>', 'row_alt_start' =>
'<tr class="alt">', 'row_alt_end' => '</tr>', 'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>', 'table_close' => '</table>');
$this->table->set_template($tmpl);
$this->table->set_caption("Work Items");
//-- Header Row
$this->table->set_heading('ID', 'Date', 'Title', 'Done', 'Item');
//-- Content Rows
$data['title'] = 'Page Display';
$this->load->view('work_links', $data);
注意它指向work_links,視圖
下一個功能是本
function done()
{
$data = array();
if ($query = $this->work_m->dead_work()) {
$data['dead'] = $query;
}
$tmpl = array('table_open' =>
'<table border="0" cellpadding="0" cellspacing="0">', 'heading_row_start' =>
'<tr class="heading">', 'heading_row_end' => '</tr>', 'heading_cell_start' =>
'<th>', 'heading_cell_end' => '</th>', 'row_start' => '<tr>', 'row_end' =>
'</tr>', 'cell_start' => '<td>', 'cell_end' => '</td>', 'row_alt_start' =>
'<tr class="alt">', 'row_alt_end' => '</tr>', 'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>', 'table_close' => '</table>');
$this->table->set_template($tmpl);
$this->load->view('work_links', $data);
}
他們背後的模型是基本通話費第一碼到數據庫
現在,這個代碼在視圖中隨着fi上述第一個功能(在文章DIV)和完美的作品
foreach($result as $row)
{
$this->table->add_row(
anchor("work/fill_form/$row->id", $row->id),
$row->date,
$row->title,
$row->compl,
$this->typography->auto_typography($row->item)
);
}
$table = $this->table->generate();
echo $table;
這是第二個代碼進入一旁的div(與上面的第二個functiin雲)
if (isset($dead)){
foreach($dead as $row)
{
$this->table->add_row(
$row->id,
$row->title,
$row->finish
);
}
}
$this->table->set_heading('ID', 'Title');
$table = $this->table->generate();
echo $table;
最後一個代碼只無論我做什麼,都會從第一個函數中獲取數據。
您是否嘗試過只調用中的第一個其他的控制器功能? – Franz 2009-11-12 00:55:44
你甚至可以使用一個類變量,而不是'$ data',雖然這可能有點髒... – Franz 2009-11-12 00:57:08
我真的試圖讓你想說什麼......我不能..你可以把一些代碼,這樣我們至少可以看到你做了什麼? – 2009-11-12 01:13:59