问题
I've used CodeIgniter before and it's been quite a long time since I've last used it so I'm basically going back to step 1.
I have the controller CaseCon with the following codes
public function index()
{
$this->load->view('CaseView');
}
public function sendTicket() {
echo "This is sendTicket function";
}
and my html page has the following code
<form method="POST" action="<?php echo site_url('CaseCon/sendTicket');?>">
<input id="full_name" type="text" class="validate" name="Name" value="Name" />
<input type="submit" value="Submit" />
</form>
I'm trying to run this on a local server. Upon clicking the submit button, the page reloads and changes the localhost:8888
to [::1]
. I'm not sure which part do I have an error. I'm getting the expected output if I force the url to go to /index.php/CaseCon/sendTicket
.
Kindly advise. Thanks.
回答1:
I would think You have your base_url blank.
$config['base_url'] = '';
That is why [::1]
You don't have set your base_url but that is what will happen
Set your base url
$config['base_url'] = 'http://localhost/your_project_name/';
Or
$config['config_base_url'] = 'http://localhost:8888/your_project_name/';
Note: Your class and file name only have first letter upper case.
File name: Casecon.php
class Casecon extends CI_Controller {
public function index() {
}
}
It might work on localhost the way you have it but on some live servers you will run into issue.
View form
<form method="POST" action="<?php echo base_url('casecon/sendTicket');?>">
<input id="full_name" type="text" class="validate" name="Name" value="Name" />
<input type="submit" value="Submit" />
</form>
How to create a Controller
How to create a Model
来源:https://stackoverflow.com/questions/35349416/site-url-changes-localhost-to-1