php - Is it ideal to transfer variables from the View page to the Controller page in codeigniter? -


i'm using codeigniter's mvc build form logged in users can post questions.

i using form allows logged in users insert data in mysql table called questions (table structure shown below).

questions table

______________________________________________ | id   |    user id  | description | category | |---------------------------------------------| |1     |      22     |  car parts  |   12     | |---------------------------------------------| |2     |      54     |  car parts  |   8      | |---------------------------------------------| |3     |     112     |  car parts  |   11     | |_____________________________________________| 

once user submits form, user's id , category_id (from table below "users table") inserted questions table above

users table

___________________________________ | id   |    user id  |category_id | |------------------------------- |1     |      22     |    12      | |------------------------------   | |2     |      54     |    54      | |----------------------------     | |3     |     112     |    8       | |_________________________________| 

my controller page code

 $this->load->model('questions_page');     $data['page_detail']  = $this->questions_page->get_business_page_by_pid($page_id);      if ($this->form_validation->run() == false || $form_validation == false)         {             $data['form_value'] = array(                 'country'        => $this->input->post('description'),                 'street_address' => $this->input->post('street_address'),                 'post_code'      => $this->input->post('post_code'),             );             $this->load->view('template', $data);         } 

this view page

<input type="text" name="post_code" value="<?= $form_value['description'] ?>">                     <?php echo form_error("description"); ?> <input type="text" name="post_code" value="<?= $form_value['street_address'] ?>">                     <?php echo form_error("street_address"); ?>     <?php // gathered info users table below needs inserted questions table     ////////////////////////////     ///////////////////////////     $page_detail->category_id;     ////////////////////////////     ///////////////////////////              ?> 

my problem have data in view page in last line ( $page_detail->category_id; ) i'd transfer controller page can insert in mysql table using $data['form_value'] = array(); shown in controller page.

how do this?

is transferring data view controller safe?

thanks in advance

1st : storing user id in question table there created relationship between 2 table can join 2 table user id can category id user table . no need store category id in question table .it's unnecessary . if store . it's called data redundancy.

2nd : guess user id session .

3rd : still want pass category_id view controller means use hidden input

 <input type='hidden' name="category_id" value="<?php echo  $page_detail->category_id; ?>" /> 

in controller :

$data['form_value'] = array(                 'country'        => $this->input->post('description'),                 'street_address' => $this->input->post('street_address'),                 'post_code'      => $this->input->post('post_code'),                 'category_id'    => $this->input->post('category_id'),                 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^          ); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -