Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sending parameter from controller to view

Is there any way to send data from controller to view. what I am doing is that user has the option of links and according to links user clicks the corresponding data is passed to the controller and another view is loaded from controller corresponding to that link. But I dont know how to do that. I am using bonfire here is my controller code :-

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

In my model part :-

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

My views are :-

<?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
   } 
   ?>

In my full_post controller function I want the parameter which the user clicks in the link click to see. helpdesk is my controller name. helpdesk_model is my model name. and my_tickets is my view name..

like image 423
avinashse Avatar asked Nov 13 '22 02:11

avinashse


1 Answers

I am doing this with the help of form using hidden fields:- I have slightly change my view page like this :-

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

and In controller page I am doing :-

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

this is the thing I need, is this good way to do it..? Is there any other better idea to do it..?

like image 179
avinashse Avatar answered Nov 23 '22 23:11

avinashse