Reputation: 21
I have a two controller function, Index function and generateReport function, when I click the export button it should direct me to this URI index.php/schoolScoreCardReport/generateReport, the problem is it directs me to this URI index.php/generateReport, i dont know why, here is my code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class schoolScoreCardReport extends PG_Controller {
public function __construct(){
parent::__construct();
}
public function index(){
if(isset($_POST['Export'])){
$this->generateReport();
}
$this->layout->view('report/index');
}
public function generatePOMEDetailReport(){
$this->layout->view('test/index');
}
}
Pls help me thankyou here is my html view for index function
<table>
<?php echo form_open('schoolScoreCardReport'); ?>
<tr><td>
<label>Region:</label>
<select name="region_name" style="width:150px">
<option value = "1">a</option>
</select>
</td></tr>
<tr><td>
<input type="submit" id="btn_export" value="Export" name="Export">
</td></tr>
<?php echo form_close(); ?>
</table>
Upvotes: 0
Views: 65
Reputation: 126
in form_open u need to follow this
<?php echo form_open('ControllerName/FunctionName'); ?>
in your case it is
<table>
<?php echo form_open('schoolScoreCardReport/generatePOMEDetailReport'); ?>
<tr><td>
<label>Region:</label>
<select name="region_name" style="width:150px">
<option value = "1">a</option>
</select>
</td></tr>
<tr><td>
<input type="submit" id="btn_export" value="Export" name="Export">
</td></tr>
<?php echo form_close(); ?>
</table>
Upvotes: 0
Reputation: 571
Unless you have some routes going on to affect the requests, I believe the parameter sent to form_open() should be as follows...
<?php echo form_open('schoolScoreCardReport/generatePOMEDetailReport'); ?>
As generatePOMEDetailReport is the only function shown in your controller code above other than the index function.
If you really want it to call the index function so the IF $post check is done, try 'schoolScoreCardReport/index' for the parameter.
Upvotes: 1
Reputation: 1
I think there is a one-to-one relationship between a URL string and its corresponding controller class/method in codeigniter. The segments in a URI normally follow this
example.com/class/function/id/
or you see this link :https://www.codeigniter.com/userguide3/general/routing.html
Upvotes: 0