繁体   English   中英

如何在Codeigniter中传递表单动作

[英]How to pass form action in codeigniter

我在codeigniter中有问题。

当我通过这样的形式:

<form name ="register" action="home/register" method="post"> 
</form>

它将产生错误:

找不到对象。

但是当我通过这样的形式:

<form name ="register" action="index.php/home/register" method="post"> 
</form>

它对我来说将是完美的。

我应该进行哪些更改,以便不通过index.php就可以正常工作?

修改项目根目录中的.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]

这是EllisLab论坛上讨论的主题

<form name ="register" action="<?php echo base_url()."home/register";?> method="post"> 
</form>

如果要从URL删除index.php,则可以创建.htaccess文件( http://ellislab.com/codeigniter/user-guide/general/urls.html

默认情况下,index.php文件将包含在您的URL中:

example.com/index.php/news/article/my_article您可以通过使用带有一些简单规则的.htaccess文件来轻松删除此文件。 这是使用“负”方法的此类文件的示例>,其中,除了指定的>项目外,所有其他内容都将被重定向:

RewriteCond上的RewriteEngine $ 1!^(index.php | images | robots.txt)RewriteRule ^(。*)$ /index.php/$1 [L]在上面的示例中,除index.php,images之外的任何HTTP请求,并且robots.txt被视为对您的index.php文件的请求。

另外,有两种方法可以做到这一点。

表格助手

CodeIgniter有一个内置的Form Helper来创建表单标签:form_open()。 http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html

URL助手

CodeIgniter具有内置的URL帮助器,用于自动执行URL路径:site_url()。 http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

在codeigniter中,有一个名为site_url(“ controller / action / arg1 /../ argn”)的帮助程序函数。

对于你的情况应该是

<form name ="register" action="<?php echo site_url("home/register") ?>" method="post"> 
</form>

有关更多详细信息,请单击此链接

http://ellislab.com/codeigniter%20/user-guide/helpers/url_helper.html

您可以像这样传递链接,它对我的​​代码来说是完美的

<form name ="register" action="<?php cho base_url()?>home/register" method="post"> </form>

请记住,必须在域或服务器地址中设置config base_url路径,并在htaccess中定义clear。

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM