Php 如何在codeigniter中传递表单动作
我在codeigniter中遇到了一个问题 当我像这样通过表格时:Php 如何在codeigniter中传递表单动作,php,codeigniter,Php,Codeigniter,我在codeigniter中遇到了一个问题 当我像这样通过表格时: <form name ="register" action="home/register" method="post"> </form> <form name ="register" action="index.php/home/register" method="post"> </form> 它将生成以下错误: 找不到任何对象 但当我通过这样的表格时: <for
<form name ="register" action="home/register" method="post">
</form>
<form name ="register" action="index.php/home/register" method="post">
</form>
它将生成以下错误:
找不到任何对象
但当我通过这样的表格时:
<form name ="register" action="home/register" method="post">
</form>
<form name ="register" action="index.php/home/register" method="post">
</form>
这对我来说会很好用的
我应该做哪些更改,使其在不传递index.php的情况下工作?如果要从URL中删除index.php,可以创建一个.htaccess文件() 默认情况下,index.php文件将包含在URL中: example.com/index.php/news/article/my_article 通过使用带有一些简单规则的.htaccess文件,可以轻松删除此文件。下面是这样一个文件的示例>,使用“否定”方法,除了指定的>项之外,所有内容都被重定向: 重新启动发动机 1美元^(index.php | images | robots.txt) 重写规则^(.*)$/index.php/$1[L] 在上面的示例中,除了index.php、images和robots.txt之外的任何HTTP请求都是 视为对index.php文件的请求 或者,有两种方法可以做到这一点 表单助手 CodeIgniter有一个内置的表单助手来创建表单标记:Form_open()。 URL帮助程序 CodeIgniter有一个内置的URL帮助程序来自动化URL路径:site_URL()。
如果要从URL中删除index.php,可以创建一个.htaccess文件() 默认情况下,index.php文件将包含在URL中: example.com/index.php/news/article/my_article 通过使用带有一些简单规则的.htaccess文件,可以轻松删除此文件。下面是这样一个文件的示例>,使用“否定”方法,除了指定的>项之外,所有内容都被重定向: 重新启动发动机 1美元^(index.php | images | robots.txt) 重写规则^(.*)$/index.php/$1[L] 在上面的示例中,除了index.php、images和robots.txt之外的任何HTTP请求都是 视为对index.php文件的请求 或者,有两种方法可以做到这一点 表单助手 CodeIgniter有一个内置的表单助手来创建表单标记:Form_open()。 URL帮助程序 CodeIgniter有一个内置的URL帮助程序来自动化URL路径:site_URL()。
在codeigniter中有一个名为site\u url(“controller/action/arg1/。/argn”)的助手函数 你的情况应该是这样的
<form name ="register" action="<?php echo site_url("home/register") ?>" method="post">
</form>
在codeigniter中有一个名为site\u url(“controller/action/arg1/。/argn”)的助手函数
你的情况应该是这样的
<form name ="register" action="<?php echo site_url("home/register") ?>" method="post">
</form>
修改项目根目录中的.htaccess文件
RewriteEngine on
# Hide the application and system directories like Javascript and CSS
RewriteCond $1 !^(index\.php|[Javascript / CSS]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
修改项目根目录中的.htaccess文件
RewriteEngine on
# Hide the application and system directories like Javascript and CSS
RewriteCond $1 !^(index\.php|[Javascript / CSS]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
您可以像这样传递链接,它对我的代码非常有用
您可以像这样传递链接,它对我的代码非常有用
当我们提交表单时,你不能理解我的观点,我们必须只传递conteroler name和action name,但我还必须传递index.php,否则它将生成错误action=“home/register”如果我这样传递,那么它将生成errorCorrect,因此,您需要我提出的关于.htaccess的第一个建议-这将删除URL中包含index.php
的要求。您无法理解我当时提交表单时的观点,我们必须只传递conteroler name和action name,但我还必须传递index.php,否则会生成错误action=“家庭/登记“如果我这样通过,那么它将生成errorCorrect,因此您将需要我提出的关于.htaccess的第一个建议-这将删除从URLsUsesite\u url
中包含index.php
的要求,由sanjong回答,如果您没有使用.htaccess
。如果您没有使用.htaccess
,请使用sanjong回答的站点url
。