CodeIgniter的URI和表单操作 [英] CodeIgniter's URI and form action

查看:62
本文介绍了CodeIgniter的URI和表单操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们在

somesite.com/mail

这意味着我们使用名为mail的控制器。此控制器具有以下功能:

it means we are using controller named 'mail'. This controller has function:

public function index(){ 
        $this->load->view('header');
        $this->load->view('mail/contact_form');
        $this->load->view('footer');

    }

此函数在我们输入地址栏时加载

This function is loaded when we type in adress bar just

somesite.com/mail

并按Enter键(无附加参数)。让我们看看contact_form视图的第一行:

and press enter (no additional arguments). And let's see first line of the contact_form view:

<form role="form" method="post" action="sendmail">

这是我的问题。当我用反斜杠键入地址时,如下所示:

And that's my problem. When I type adress with backslash on the end like this:

mysite.com/mail/

并使用我的联系人公式,一切正常,我的邮件控制器加载函数sendmail,现在的URL是:

and use my contact formula, everything works good and my Mail controller loads function sendmail and the URL is now:

mysite.com/mail/sendmail/

但是当我忘记反斜杠(mysite.com/mail),它寻找的控制器名为sendmail,但我不想要它。我的网址为:

But when I forget about backslash (mysite.com/mail), it looks for controller named "sendmail" but I don't want it. My url is then:

mysite.com/sendmail

但是我没有任何控制器名为sendmail。我的问题是 - 如何改变我的公式的行动或我该怎么做,使这工作良好?是唯一的答案记住反斜杠或什么?

but of course I don't have any controllers named sendmail. My question is - how to change action of my formula or what should I do to make this working good? Is the only answer to remember about backslash or what?

推荐答案

作为简单的例子给你是使用CI的 site_url()

As simple example as to give you is to use CI's site_url()

site_url(controller / function)它会照顾其他url事情

site_url("controller/function") and it will take care of other url things

<form role="form" method="post" action="<?php echo site_url('mail/sendmail');?>">

浏览 url_helper

这篇关于CodeIgniter的URI和表单操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆