![]() |
codeigniter parser php issue and set value in form - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: codeigniter parser php issue and set value in form (/showthread.php?tid=65056) |
codeigniter parser php issue and set value in form - vladakg - 04-24-2016 I use Codeigniter 2.x and this is function in my controller: Code: $query = $this->users_mod->changeProductData($idPro); In template view I call another view with this method: Code: <div class="container-fluid main-body"> And on the end in view editproduct.php I list data in form. But I have problem how to set value in form when form validation show some errors to still keep data in field. I done that like this before I start use parse: Code: <label class="radio-inline"><input type="radio" name="active" id="active1" value="0" class="radio" <?php if($row->active==0) { echo set_radio("active", "0", true); } else { echo set_radio("active", "0"); } ?>>inactive</label> I have two question: 1. As you can see in template.php I can write php code and call variable (<?= $ap_content), but that doesn't work in view editproduct.php. Can I somehow use another variable from array in editproduct.php with php tag? 2. Can I somehow in controller in array write some variable with php code. For example: 'ap_var' = '<?php echo set_radio("active", "0", true); ?>' and call that variable in editproduct.php as {ap_var}? RE: codeigniter parser php issue and set value in form - mwhitney - 04-27-2016 1. PHP Code: 'ap_content' => $this->load->view('editproduct', '', true) The second parameter of $this->load->view() is the data you are passing to the view (and this is supposed to be an array or object). Since you're loading the view into $data['ap_content'] when initially defining the $data array, you can't pass anything from $data into the view. You could do something like this, though: PHP Code: $query = $this->users_mod->changeProductData($idPro); Note that you still wouldn't be able to access $ap_content within the editproduct view, since the 'ap_content' key wasn't set in $data when the editproduct view was loaded (and, since the content of $ap_content is the editproduct view, I wouldn't expect that to work out very well, anyway). 2. PHP Code: 'ap_var' = '<?php echo set_radio("active", "0", true); ?>' You could do something like this: PHP Code: $data = array( However, using the form helper functions this way feels really awkward. |