this is my first time to use codeigniter to make a web site. My problem is as follow:
My view file contains:
<label class="control-label ">Insert Number of photos : </label>
<?php echo form_open('project_controller/no_of_pics'); ?>
<input name="no_pics" placeholder="Insert a number" type="text" value="<?php echo set_value('no_pics'); ?>" >
<input type='submit' name='submit' value='Insert' />
<?php echo form_close() ?>
<?php $no_pic=''; ?>
<?php echo $no_pic; ?>
<br><br>`
My controller file contains:
public function no_of_pics(){
$this->load->view('control_panel');
$number=$this->input->post('no_pics');
$hoho = array('no_pic' => $number );
$this->load->view('control_panel',$hoho);
}
and I wrote that line the .htaccess file:
$route['project_controller/no_of_pics'] = "/project_controller/no_of_pics";
my problem is that I can't get the no_pics back to the view, it is supposed to check the number through validation rules in the controller but I want firstly to get the number back to the view file
when I wrote the code above I get the number back but in a plain page of the view file without any styling and in the top the number I inserted in the input form not even where I want to use.
3-01-2015 I think I knew what the problem is, but I still don't know how to fix it . I have an other method in that controller "project_controller" is:
public function project($page = 'home'){
if ( ! file_exists ('application/views/'.$page.'.php')){
show_404();
}
$this->load->view($page);
}
and I wrote in the route.php file:
$route['(:any)'] = 'project_controller/project/$1';
so I think the problem is "function no_of_pics()"
can not view the page properly when sending a variable to it as function project()
is responsible for that , so what is the solution now?
You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a value for the form.check here
set_value('no_pics',$no_pic);
You need to remove this line from view file
<?php $no_pic=''; ?>
It reset the variable that passes from the controller.
You can try this technique
$hoho['no_pic'] =$number;
$this->load->view('control_panel',$hoho);
I think then you find it on view page.