2012-07-16 54 views
5

有什麼方法可以將數據從控制器發送到查看。 我在做什麼是用戶有鏈接的選項,並根據鏈接用戶點擊相應的數據傳遞給控制器​​和另一個視圖從控制器加載相應的鏈接。 但我不知道該怎麼做。 我使用篝火 這裏是我的控制器代碼: -從控制器發送參數到查看

function my_tickets() { 
     $username = $this->auth->username(); 
     $this->load->model('helpdesk_model'); 
     $result_set = $this->helpdesk_model->my_tickets($username); 
     foreach($result_set->result() as $data) { 
      $title[] = $data->title; 
      $category[]=$data->category; 
      $priority[]=$data->priority; 
      $date[]=$data->date; 
      $post_status[]=$data->post_status; 
      $userfile_path[] = $data->userfile_path; 
     } 
     $arraysize=count($title); 
     Template::set('arraysize',$arraysize); 
     Template::set('title',$title); 
     Template::set('category',$category); 
     Template::set('priority',$priority); 
     Template::set('date',$date); 
     Template::set('post_status',$post_status); 
     Template::set('username',$this->auth->username()); 
     Template::set('userfile_path',$userfile_path); 
     Template::render(); 
    } 
    function full_post(){ 
     Template::render(); 
    } 
    } 

在我的模型的一部分: -

function my_tickets($username){ 
     $this->db->select('title,userfile_path,category,priority,date,post_status'); 
     $this->db->where('username',$username); 
     $result = $this->db->get('tbl_tickets'); 
     return $result; 
     } 

我的觀點是: -

<?php 
$arraysize =Template::get('arraysize'); 
$title[] = Template::get('title'); 
$category[]=Template::set('category'); 
$priority[]=Template::set('priority'); 
$date[]=Template::set('date'); 
$post_status[]=Template::set('post_status'); 
$username = Template::set('username'); 
$userfile_path = Template::set('userfile_path'); 
?> 
<h3>Total Number Of posts :&nbsp; <?php echo $arraysize; ?> </h3> 
<h2>Your Posts</h2> 
<?php echo "serail. title | category | priority | date of starting post | post status "; ?> 
<?php 
    for ($i=0; $i <$arraysize; $i++) { 
    ?> 
    <p> <?php echo ($i+1).". ".$title[$i]." | ".$category[$i]." | ".$priority[$i]." | ".$date[$i]." | ".$post_status[$i]; 
      echo "<a href=\"/helpdesk/full_post\">Click to see </a>"; 
     ?> 
    </p> 
    <?php 
    } 
    ?> 

在我full_post控制器功能我需要用戶在鏈接click to see中點擊的參數。 服務檯是我的控制器名稱。 helpdesk_model是我的模型名稱。和 my_tickets是我的視圖名稱。

回答

1

我與形式的幫助下使用隱藏域這樣做: - 我稍微改變我的視圖頁是這樣的: -

for ($i=0; $i <$arraysize; $i++) { 
    echo "<p>".($i+1).". ".$title[$i]." | ".$category[$i]." | ".$priority[$i]." | ".$date[$i]." | ".$post_status[$i]."</p>"; 
    echo form_open('/helpdesk/full_post'); 
    echo form_hidden('path',$userfile_path[$i]); 
    echo form_submit('submit', 'click to see'); 
    echo form_close(); 
    } 

,並在控制器頁我做: -

function full_post(){ 
     Template::set('path',$this->input->post('path')); 
     Template::render(); 
     } 

這是我需要的東西,這是做這件事的好方法..? 有沒有其他更好的想法做到這一點..?

0

使用參數創建一個控制器函數並提供帶有參數的鏈接。

echo anchor('controller/functionName/parameter','display text'); 

function functionName($parameter ='') 
{ 
    //Do something with the parameter here when user click on the displayed text. 
} 

我不確定,如果這是你想要的,因爲這是很容易的事情。

+0

不,我不想要這個。我想發送一些值從視圖到控制器,價值是用戶點擊的鏈接.. 假設在我看來我有3個鏈接a,b和c,如果用戶點擊一個然後控制器函數將被調用,並相應的值到a將從視圖傳遞到該功能 – avinashse 2012-07-16 10:34:56

+0

是的,可以使用上述技術來完成。如果你創建一個鏈接到http://yoursite.com/controller/function/a,那麼a將被傳遞給函數。同樣的方式可以有另一個環節b。你的意思是通過使用Ajax? – Nish 2012-07-16 11:10:01

+0

實際上我不想在參數中傳遞我的細節,那就是...... 沒有ajax會顯示同一頁面中的內容,但我必須從控制器調用另一個視圖 – avinashse 2012-07-16 11:16:08