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は私のビュー名です。

4

2 に答える 2

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();
        }

これは私が必要とするものです、これはそれを行うための良い方法ですか..?それを行うための他のより良いアイデアはありますか..?

于 2012-07-16T11:14:54.037 に答える
0

パラメーターを使用してコントローラー関数を作成し、パラメーターを含むリンクを提供します。

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

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

これはとても簡単なことなので、これがあなたが望むかどうかはわかりません。

于 2012-07-16T10:30:43.090 に答える