2012-07-16 55 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