douxin1163 2012-04-25 16:01
浏览 27
已采纳

控制器在CodeIgniter中的URL中重复

I have a Controller called Register that looks like this:

class Register extends CI_Controller
{
    public function index()
    {
        $this->load->view('register');
    }

    public function create()
    {
        $this->load->library('form_validation');
        //set rules here

        if ($this->form_validation->run() == TRUE)
        {
            //everything checks out
        }
        else
        {
            $this->load->view('register');
        }
    }
}

The view contains a form that posts to register/create.

My problem is, when I go to localhost/register and fill out the form incorrectly, the form reloads, but the url is now:

localhost/register/register/create

If I enter it incorrectly again

localhost/register/register/register/create

and so on...

I'm guess this is an htaccess and I've tried using some standard CodeIgniter htaccess files available online, but none fix this issue. I'm using this on a WAMP server.

EDIT

The view file only consists of the form, for now. I prefer using direct HTML instead of the CodeIgniter Form helper.

<form id="register_form" method="post" action="register/create" title="Create an Account">
    <!-- input fields -->
</form>
  • 写回答

3条回答 默认 最新

  • duanla8800 2012-04-25 16:18
    关注

    Use full url. Either current_url() or site_url('register') in your form's action.

    It's good practice you use either of these or preffix with base_url() since that allows your site to run without having to be the domain path.
    For instance you can, if needed run the site on example.com/my_site/ instead of only being able to run on example.com.

    For fullest possible control of your form's action, always start on http:// and avoid relative urls (action="register" for instance).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据