我是CodeIgniter的新手。無法使控制器和查看註冊表一起工作
目前我有一個register.php(VIEW)和一個register.php(CONTROLLER)。 register.php(VIEW)包含一個簡單的表單,從這個表單我試圖傳遞數據到控制器,以便將其插入數據庫。簡單。
每當我加載視圖時,我似乎得到的是與變量和函數有關的不同錯誤消息,也是我嘗試加載視圖的錯誤。
我只是問:
- 這是正確的方法是使用控制器和視圖在一起嗎?
- 我該如何解決這個當前的問題?
下面是兩個文件:
register.php(VIEW)
<htmL>
<body>
<form method="post" action="controllers/register.php">
<input type="text" name="email">
<input type="text" name="name">
<input type="password" name="password">
<select id="userLevel" name="userLevel">
<option value="2">Job Seeker</option>
<option value="3">Employer</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</htmL>
register.php(控制器)
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Users extends CI_Controller{
public function __construct(){
public $email;
public $name;
public $password;
public $userLevel;
$this->email = $_POST['email'];
$this->name = $_POST['name'];
$this->password = $_POST['password'];
$this->userLevel = $_POST['userLevel'];
}
public function createuser() {
if(filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
$this->db->set('email', $this->email);
$this->db->set('name', $this->name);
$this->db->set('password', $this->password);
$this->db->set('userLevel', $this->userLevel);
$this->db->insert('users');
}
}
$this->load->view('register');
}
?>
你爲什麼要定義類在構造函數中的變量?您可能想打開錯誤報告並查看錯誤日誌中的內容。 –
@tereško我敢肯定,我提到我是一名初學者,所以如果你可以幫忙,而不是問這些問題。 – AyeTry
不,我現在會回答正確的方法 –