从控制器发送参数到视图

时间:2012-07-16 10:22:49

标签: php html codeigniter parameters hyperlink

有没有办法从控制器发送数据到视图。 我正在做的是用户可以选择链接,根据链接用户点击,相应的数据传递给控制器​​,另一个视图从对应于该链接的控制器加载。 但我不知道该怎么做。 我在用篝火 这是我的控制器代码: -

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是我的观点名称..

2 个答案:

答案 0 :(得分: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();
        }

这是我需要的东西,这是做这件事的好方法吗? 还有其他更好的主意吗??

答案 1 :(得分:0)

使用参数创建控制器函数,并在其中提供带参数的链接。

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

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

我不确定,如果这是你想要的,因为这很容易。

相关问题