我试图从模型到控制器从数据库细节获取数据我没有得到 它是说Undefined变量:结果可以让任何人知道如何从模型到控制器获取数据吗?
Controller.php这样
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('login_model');
$this->load->helper(array('form', 'url'));
$this->load->library('session');
}
public function setting()
{
$this->load->database();
session_start();
$userss="";
if($_SESSION["registerid"])
{
$userss = $_SESSION["registerid"];
}
$this->load->model('setting_model');
$this->setting_model->getsetting($userss);
$data12345 = array(
'registerid' => $result[0]->registerid,
'username' => $result[1]->username,
'email' => $result[2]->email,
'password' => $result[3]->password,
'companyname' => $result[0]->companyname,
'phonenumber' => $result[0]->phonenumber ,
'address' => $result[0]->address,
'postalcode' => $result[0]->postalcode,
'descriptionofcompany' =>$result[0]->descriptionofcompany,
'creditcardinformation' =>$result[0]->creditcardinformation,
'title'=>'Setting Page'
);
//passing page title
$this->load->helper('url'); // passing base url
$this->load->view('setting',$data12345); // passing setting.php view
}
}
setting_model.php
<?php
class setting_model extends CI_Model{
function __construct() {
parent::__construct();
}
public function getsetting($userss) {
$this->load->database();
$condition = "username =" . "'" . $userss . "'";
$this->db->select('*');
$this->db->from('register');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}
// Read data from database to show data in admin page
}//end class
?>
答案 0 :(得分:1)
您似乎忘了将查询结果分配给$ result变量。在控制器中试试这个$result = $this->setting_model->getsetting($userss);
。