I'm new in codeigniter. I want to save something database. I have link localhost/index.php/blog/gerilim_controller/40 I want to save 40 to database.
I wrote some code. This is my model code: Akim_model.php;
<?php
class Akim_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function ekle($data)
{
$ekle=$this->db->insert('gerilim',$data);
if($ekle){
return 1;
}else{
return 0;
}
}
}
?>
This is my controllers code: Blog.php;
<?php
class Blog extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper('url'); }
public function gerilim_controller( $gerilim_id = NULL ) {
echo $gerilim_id;
$data=array('gerilim'=>$this->input->post('gerilim'));
$this->load->model('akim_model');
$sonuc=$this->akim_model->ekle($data);
if($sonuc==1)
echo "Successed";
else
echo "Failed";
}
}
?>
But when $this->load->model('akim_model');
its gives an error. Where I am wrong?
THe file name must match the class name for your model:
<?php
class Akim_model extends CI_Model {
function __construct() {
parent::__construct();
$this->load->database();
}
function ekle($data) {
$ekle=$this->db->insert('gerilim',$data);
if($ekle) {
return 1;
}
else{
return 0;
}
}
}
?>
Also put your conditional statement in curly braces:
if($sonuc==1) {
echo "Successed";
}
else {
echo "Not successed";
}
You should call your model using the class name:
$this->akim_model->ekle($data);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.