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