site_url changes localhost to [::1]

扶醉桌前 提交于 2019-12-31 04:07:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!