[英]codeigniter displaying form_open
I am trying to learn codeigniter and for some reason I can't do the simplest of things.我正在尝试学习 codeigniter,但出于某种原因,我无法做最简单的事情。
Basically I am creating a form on a login page.基本上我在登录页面上创建一个表单。 But I am getting
但我越来越
Fatal error: Call to undefined function validation_errors() in A:\\work\\codeigniter\\ci\\application\\views\\pages\\login.php on line 5
致命错误:在第 5 行调用 A:\\work\\codeigniter\\ci\\application\\views\\pages\\login.php 中未定义的函数 validation_errors()
and if I comment out the validation_errors line, I get如果我注释掉 validation_errors 行,我会得到
Fatal error: Call to undefined function form_open() in A:\\work\\codeigniter\\ci\\application\\views\\pages\\login.php on line 5 ...
致命错误:在第 5 行调用 A:\\work\\codeigniter\\ci\\application\\views\\pages\\login.php 中未定义的函数 form_open() ...
Error message错误信息
( ! ) Fatal error: Call to undefined function validation_errors() in A:\work\codeigniter\ci\application\views\pages\login.php on line 3
Call Stack
# Time Memory Function Location
1 0.0004 697328 {main}( ) ..\index.php:0
2 0.0010 790176 require_once( 'A:\work\codeigniter\ci\system\core\CodeIgniter.php' ) ..\index.php:202
3 0.0135 2313080 call_user_func_array ( ) ..\CodeIgniter.php:359
4 0.0135 2313160 Pages->view( ) ..\CodeIgniter.php:359
5 0.0135 2313288 CI_Loader->view( ) ..\pages.php:9
6 0.0135 2314232 CI_Loader->_ci_load( ) ..\Loader.php:419
7 0.0138 2363392 include( 'A:\work\codeigniter\ci\application\views\pages\login.php' ) ..\Loader.php:833
This is my code:这是我的代码:
login.php located at view\\pages login.php 位于 view\\pages
<?php echo validation_errors(); ?>
<?php echo form_open('user/login') ?>
<label for="Id"> User Id</label>
<input type="input" name="Id" /> <br/>
<label for="Password">User Password</label>
<input type="input" name="Password" />
<br/>
<input type="submit" name="submit" value="log in" />
</form>
user.php located at controllers\\ user.php 位于控制器\\
<?php
class User extends CI_controller{
public function login()
{
$this->load->helper('form');
$this->load->library('form_validation');
//i have a file views/pages/main.php which just says "this is main"
$this->load->view('pages/main');
}
}
pages.php located at controllers/ pages.php 位于控制器/
<?php
class Pages extends CI_Controller{
public function view($page){
if(!isset($page)||!file_exists("application/views/pages/$page.php")){
show_404();
}
$this->load->view("pages/$page");
}
}
routes.php located at config/ route.php 位于 config/
$route['default_controller'] = "pages/view";
$route['(:any)']="pages/view/$1";
$route['404_override'] = '';
this is what I think happens and if I am wrong, please correct me.这就是我认为发生的事情,如果我错了,请纠正我。 form_open('user/login') makes the "action" of the html form element point to a method "login" of class "user" located in controlers.
form_open('user/login') 使 html 表单元素的“action”指向位于控制器中的类“user”的方法“login”。
also, I googled a lot and pretty much everyone else that was getting this error was getting it because they hadnt done另外,我在谷歌上搜索了很多,几乎所有其他收到此错误的人都收到了,因为他们还没有完成
$this->load->helper('form');
$this->load->library('form_validation');
Also, I don't get the string in form_open points to the location for the "action" attribute in the html form element.另外,我没有得到 form_open 中的字符串指向 html 表单元素中“action”属性的位置。 Why is it neccessary to load form helper and form validation library there?
为什么需要在那里加载表单助手和表单验证库? Can someone explain the flow of this, please?
有人可以解释一下这个流程吗?
basically the problem was that the controller that was calling the view with the form should contain基本上问题是使用表单调用视图的控制器应该包含
$this->load->helper('form');
$this->load->library('form_validation');
and not the controller that is being called by the form action而不是表单操作调用的控制器
Try loading form helper at your autoload.php
file inside config
folder.尝试在
config
文件夹内的autoload.php
文件中加载表单助手。
This would be a good practise:这将是一个很好的做法:
$autoload['helper'] = array('url','text','form');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.