This is my Model:
class Medecin_model extends CI_Model
{
public $fillable = array('nom','prenom','genre','adresse','date_naissance','specialiter','servise','grade','etablissement','type_personne');
public $id_medecin;
public $nom;
public $prenom;
public $genre;
public $adresse;
public $date_naissance;
public $specialiter;
public $service;
public $grade;
public $etablissement;
public $type_personne = Medecin;
public function insert($nom, $prenom, $genre, $adresse, $date_naissance, $specialiter, $service, $grade, $etablissement)
{
$this->nom=$nom;
$this->prenom=$prenom;
$this->genre=$genre;
$this->adresse=$adresse;
$this->date_naissance=$date_naissance;
$this->specialiter=$specialiter;
$this->service=$service;
$this->grade=$grade;
$this->etablissement=$etablissement;
// $this->db->insert('personne', $this);
}
This is my controller:
defined('BASEPATH') OR exit('No direct script access allowed');
class Medecin extends CI_Controller
{
public function index()
{
$this->load->view('header');
$this->load->view('ajout_medecin');
$this->load->view('footer');
}
public function ajout()
{
$this->load->model("Medecin_model");
$nom=$this->input->post('first-name');
$prenom=$this->input->post('last-name');
$genre=$this->input->post('genre');
$adresse=$this->input->post('adress');
$date_naissance=$this->input->post('birthday');
$specialiter=$this->input->post('speciality');
$service=$this->input->post('service');
$grade=$this->input->post('grade');
$etablissement=$this->input->post('establishment');
$doctor = new Medecin_model();
$doctor->insert($nom, $prenom, $genre, $adresse, $date_naissance, $specialiter, $service, $grade, $etablissement);
}
and i have this error message :
A PHP Error was encountered Severity: Notice Message: Use of undefined constant Medecin - assumed 'Medecin' Filename:
core/Loader.php Line Number: 357 Backtrace: File:
C:\wamp64\www\CodeIgniter\application\controllers\Medecin.php Line: 23
Function: model File: C:\wamp64\www\CodeIgniter\index.php Line: 315
Function: require_once
Missing '' around Medecin
Replace it
public $type_personne = Medecin;
With this
public $type_personne = 'Medecin';
Related
A PHP Error was encountered Severity: Notice
Message: Undefined property: Account::$Account_model
Filename: Admin/Account.php
Line Number: 19
Backtrace:
File: C:\xampp\htdocs\AdminLTE\application\controllers\Admin\Account.php
Line: 19
Function: _error_handler
File: C:\xampp\htdocs\AdminLTE\index.php
Line: 292
Function: require_once
class Account extends CI_Controller {
public function _construct() {
parent::__construct();
$this->load->model('Account_model');
}
public function index() {
$mdat=[
'active_controller' => 'master',
'active_function' => 'account/account_view',
];
$this->load->view('admin/global/menu', $mdat);
$data['books']=$this->Account_model->get_all_acc();
$this->load->view('account_view',$data);
}
this is my model :
class Account_model extends CI_Model
{
var $table = 'books';
public function acc_add($data) {
$this->db->insert($this->table,$data);
return $this->db->insert_id();
}
public function get_all_acc() {
$this->db->from('books');
$query = $this->db->get();
return $query->result();
}
Try to change your function construct to this one :
public function __construct() {
parent::__construct();
$this->load->model('Account_model');
}
because the construct function require double underscore and you just typing one underscore
I'm trying to filter the results from eloquent query, but appear the next error BadMethodCallException. According to me, I'm doing everything right.
I'm using Laravel 5.4
The error details:
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::filter()
in Builder.php line 2445
at Builder->__call('filter', array(null))
in Builder.php line 1254
at Builder->__call('filter', array(null))
in web.php line 459
at Router->{closure}()
in Route.php line 189
at Route->runCallable()
in Route.php line 163
at Route->run()
in Router.php line 572
I have the next code:
public function index(SearchRequest $searchRequest, ConfigurationFilter $filters)
{
$filtered_configurations = Configuration::whereTrash(false)->with(['customs.properties', 'properties'])->filter($filters);
$types = $this->getConfigurationTypes();
$authors = $this->getAuthors();
return view('configuration.assistant.index', [
'configurations' => $filtered_configurations->paginate(10),
'authors' => $authors,
'types' => $types,
]);
}
Where SearchRequest is:
class SearchRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return Auth::user()->author != null;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
//
];
}
}
Where ConfigurationFilter is:
class ConfigurationFilter extends ModelFilter
{
public function name($value)
{
return $this->builder->where('name', 'like', "%{$value}%");
}
public function author($id)
{
return $this->builder->whereIn('user_id', explode(',', $id));
}
public function type($type)
{
return $this->builder->whereIn('category_id', explode(',', $type));
}
public function status($status)
{
return $this->builder->whereEnabled($status == 'enabled');
}
}
Where ModelFilter is:
class ModelFilter extends QueryFilter implements Filter
{
public function id($id)
{
return $this->builder->whereIn('id', explode(',', $id));
}
public function from($date)
{
return $this->builder->where('created_at', '>=', $date);
}
public function to($date)
{
return $this->builder->where('created_at', '<=', $date);
}
public function enabled($status)
{
return $this->builder->whereEnabled($status === 'true');
}
public function trash($status)
{
return $this->builder->whereTrash($status === 'true');
}
public function take($limit = 100)
{
return $this->builder->take($limit);
}
}
Where Filter is:
interface Filter {
public function id($id);
public function from($date);
public function to($date);
public function enabled($status);
public function trash($status);
public function take($limit = 100);
}
What will I be missing?
Thanks in advance
I already resolved it, I added the next function to model:
public function scopeFilter($query, QueryFilter $filters)
{
return $filters->apply($query);
}
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$U_Model
Filename: controllers/Login.php
Line Number: 24
Backtrace:
File: C:\xampp\htdocs\Cmsproject\application\controllers\Login.php
Line: 24
Function: _error_handler
File: C:\xampp\htdocs\Cmsproject\index.php
Line: 315
Function: require_once
$data=$this->U_Model->loginf($loginf['username'], $loginf['password']);
An uncaught Exception was encountered
Type: Error
Message: Call to a member function loginf() on null
Filename: C:\xampp\htdocs\Cmsproject\application\controllers\Login.php
Line Number: 24
Backtrace:
File: C:\xampp\htdocs\Cmsproject\index.php
Line: 315
Function: require_once
Model File Is Here:
<?php
class U_Model extends CI_Model
{
public function loginf($username,$pass){
$this->db->select('*');
$this->db->from('users');
$this->db->where('username',$username);
$this->db->where('password',$pass);
if($query=$this->db->get()){
return $query->row_array();
}else{
return false;
}
}
}
?>
Hope this will help you :
Your controller should be like this :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct(){
parent::__construct();
//$this->load->model('User');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->helper('url');
$this->load->database();
$this->load->model('U_Model');
}
public function index(){
$this->load->view('header');
$this->load->view('login');
$this->load->view('footer');
}
/*added public before loginp*/
public function loginp(){
$username = $this->input->post('username');
$password = md5($this->input->post('password'));
/*md5 not recommended*/
$data = $this->U_Model->loginf($username, $password);
if( ! empty($data))
{
$this->session->set_userdata('sid',$data['id']);
$this->session->set_userdata('sname',$data['name']);
$this->session->set_userdata('username',$data['username']);
redirect('login/home');
}else{
$this->session->set_flashdata('emsg','Please Enter Your Correct Name And Password');
redirect('login/home');
}
}
public function home(){
$this->load->view('home');
}
}?>
Change your model like this
<?php
class U_Model extends CI_Model
{
public function loginf($username,$pass)
{
$this->db->where('username',$username);
$this->db->where('password',$pass);
$query = $this->db->get('users')
if($query->num_rows() > 0){
return $query->row_array();
}else{
return false;
}
}
}
?>
<?php
class U_Model extends CI_Model
{
public function loginf($username,$pass)
{
$this->db->where('username',$username);
$this->db->where('password',$pass);
$query = $this->db->get('users')
if($query->num_rows() > 0){
return $query->row_array();
}else{
return false;
}
}
}
?>
Everything is working as expected on my local server, but when I try to run it on my live server I get an error:
Fatal error: Call to a member function call_admin_login() on null in codeigniter HMVC
What am I possibly doing wrong?
Below is my code:
<?php
class Admin_login extends MY_Controller {
public function __construct() {
parent::__construct();
//Check Login Status
$logged_info = $this->session->userdata('logged_info');
if ($logged_info != FALSE) {
redirect(base_url('admin/view_products.html', 'refresh'));
}
//Load Model
$this->load->model('admin_login_model', 'login_mdl');
}
public function index() {
$data['title'] = 'Admin Login';
$this->template->call_admin_login($data);
}
<?php
class Template extends MY_Controller {
public function __construct() {
parent::__construct();
}
public function call_admin_master($data = NULL) {
$this->load->view('admin_master_v', $data);
}
public function call_admin_login($data = NULL) {
$this->load->view('admin_login_v', $data);
}
}
this is my controller class
public function _construct()
{
parent::_construct();
$this->load->model('customer_model');
}
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Title', 'required');
$this->form_validation->set_rules('address', 'text', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->helper('url');
$this->load->view('templates/header');
$this->load->view('master/customer');
}
else
{
$this->customer_model->register();
//$this->load->view('news/success');
}
}
}
and this is my moodel class
class Customer_model extends CI_model
{
public function _construct()
{
$this->load->database();
}
public function register()
{
$data = array(
'name' => $this->input->post('name'),
'address' => $this->input->post('address')
);
return $this->db->insert('registration', $data);
}
}
while running codeigniter i'm getting this error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Customer::$customer_model
Filename: controllers/customer.php
Line Number: 30
Fatal error: Call to a member function register() on a non-object in C:\xampp\htdocs\CodeIgniter_2.1.3\application\controllers\customer.php on line 30
i'm new to codeigniter any body please tell me why this error is occuring
in controller & model, try changing:
public function _construct() {
....
}
to
public function __construct() { //double underscore
....
}