我正在尝试在codeigniter中启用用户注册和登录。但是得到错误
致命错误:调用中未定义的函数form_open()C: 第10行上的''examplep''htdocs''myfolder''application''views''signup_form.php
有什么建议吗我的url看起来像这个
localhost/myfolder/index.php/signup/
我创建控制器
<?php
class signup extends CI_Controller {
function Home(){
parent::Controller();
$this->load->library('form_validation');
}
public function index(){
$this->load->view('signup_form');
}
}
?>
signup_form
<!DOCTYPE html>
<html>
<head>
<title>Create Contact Form Using CodeIgniter</title>
<link href='http://fonts.googleapis.com/css?family=Marcellus' rel='stylesheet' type='text/css'>
<link href="http://localhost/CodeIgniter/css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<?php echo form_open('main_controller'); ?>
<h1>Create Contact Form Using CodeIgniter</h1>
<?php echo form_label('Student Name :'); ?>
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?>
<?php echo form_label('Student Email :'); ?>
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?>
<?php echo form_label('Student Mobile No. :'); ?>
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile')); ?>
<?php echo form_label('Student Address :'); ?>
<?php echo form_input(array('id' => 'daddress', 'name' => 'daddress')); ?>
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?>
</div>
</body>
</html>
尝试这个
function Home() {
parent::Controller();
$this->load->library('form_validation');
$this->load->helper('form');
}
public function index() {
$this->load->view('signup_form');
}
您需要加载form
帮助程序才能使用form_open
方法。
$this->load->helper("form");
编辑
如果您只需要在索引方法中,只需将其放入即可。如果您在控制器中的许多方法中都需要它,只需将它放在构造函数中即可。尽量避免加载不必要的文件。它可以减少内存消耗。
希望它对你有用。
请尝试一下。
<?php
class Signup extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('form');
$this->load->library('form_validation');
}
public function index() {
$this->load->view('signup_form');
}
}
?>
您需要像一样在父级中传递辅助数组
$this->load->helper(array('form'));
我们中的大多数人需要4种类型的函数才能在辅助数组中传递
$this->load->helper(array('text','html','url','form'));
这是基本的helper数组url,它将帮助您传递baseurl();