i try to use a function but face a problem. I make research on the Net but there’s no a solution
i have a model . You can see below:
<?php
class kayitmodel extends CI_Model {
function User_model() {
parent::Model();
}
function uyeEkle($username, $email, $password, $activationCode) {
$sha1_password = sha1($password);
$query = "insert into pasaj_register(username,email,password,activationCode) values(?,?,?,?)";
$this->db->query($query, array($username, $email, $sha1_password, $activationCode));
}
function uyeOnay($registrationCode) {
$query = "SELECT id FROM pasaj_register where activationCode = '" . $registrationCode . "' and active != 1";
$result = $this->db->query($query, $registrationCode);
if ($result->num_rows() == 1) {
$query = "UPDATE pasaj_register SET active = 1 WHERE activationCode = ?";
$this->db->query($query, $registrationCode);
return true;
} else {
return false;
}
}
function girisKontrol($username, $password) {
$sha1_password = sha1($password);
$query = "SELECT id FROM pasaj_register WHERE username = ? and password = ?";
$result = $this->db->query($query, array($username, $sha1_password));
if ($result->num_rows() == 1)
return $result->row(0)->id;
else
return false;
}
}
In giris controller i use girisKontrol function
<?php
class giris extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->model('kayit/kayitmodel');
$this->load->view('giris/giris');
}
public function main_page() {
extract($_POST);
$userID = $this->giris->kayitmodel($username, $password);
if(!userID)
echo "yok";
else
echo "var";
}
}
?>
but when page is processed it gives error :
Fatal error: Call to a member function kayitmodel() on a non-object in C:\xampp\htdocs\pasaj\application\controllers\giris.php on line 20
why ?
This is wrong.
girisis your controller, it is currently$this.kayitmodelis your model. You then need to call a function on your model.Also in your model:
should be:
EDIT: Models need to start with an uppercase letter, with the rest lowercase. Also the file name should be the class name, but all lowercase.
Manual: http://codeigniter.com/user_guide/general/models.html
This should be in a file called
kayitmodel.php(note the lowercase ‘k’).Your call should be changed to:
EDIT2: Your controller should start with an uppercase letter too.
Manual: http://codeigniter.com/user_guide/general/controllers.html
EDIT3: You need to load the model in the constructor of your controller, so all methods inside can use it.