I'm trying to extend CI_Loader class to override _ci_load_library(), but I'm receiving:
Fatal error: Class 'CI_Loader' not found in C:\Users\X\workspace\ci-app\application\core\MY_Loader.php on line 4
A PHP Error was encountered
Severity: Error
Message: Class 'CI_Loader' not found
Filename: core/MY_Loader.php
Line Number: 4
Backtrace:
The class MY_Loader is located in application/core/MY_Loader.php, and it's like this:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Loader extends CI_Loader
{
public function __construct()
{
parent::__construct();
}
protected function _ci_load_library($class, $params = NULL, $object_name = NULL)
{
// ...
}
}
I'm using the latest version of CodeIgniter: 3.1.9
Try Adding below line above declaration of class MY_Loader
require APPPATH."../system/core/Loader.php";
Related
I'm about to launch a website which I built with codeigniter3. I've made configuration changes such as base_url, database, etc. But it shows me an error like this :
Message: Undefined property: Home::$home
Filename: controllers/Home.php
Line Number: 18
Backtrace:
File: /home/u8460348/public_html/application/controllers/Home.php
Line: 18 Function: _error_handler
File: /home/u8460348/public_html/index.php Line: 294 Function:
require_once ```
Message: Call to a member function select() on null
Filename: /home/u8460348/public_html/application/controllers/Home.php
Line Number: 18
Backtrace:
File: /home/u8460348/public_html/index.php Line: 294 Function:
require_once ```
So, here is my controller :
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Home extends My_Controller
{
public function index($page = null)
{
$data['title'] = 'Home | Omid Health Style';
$data['content'] = $this->home->select(
[
'product.id', 'product.slug', 'product.title AS product_title', 'product.description',
'product.image', 'product.price', 'product.is_available', 'product.weight',
'category.title AS category_title', 'category.slug AS category_slug'
]
)
->join('category')
->where('product.is_available', 1)
->paginate($page)
->get();
$data['total_rows'] = $this->home->where('product.is_available', 1)->count();
$this->home->table = 'blog';
$data['blogs'] = $this->home->select(
[
'blog.id', 'blog.slug', 'blog.title AS blog_title', 'blog.description', 'blog.content',
'blog.image', 'blog_category.title AS blog_category_title', 'blog_category.slug AS blog_category_slug'
]
)
->join('blog_category')
->paginate($page)
->get();
$data['total_rows'] = $this->home->count();
$data['page'] = 'pages/home/index';
$this->view($data);
}
}
Here is my Home_model.php :
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Home_model extends MY_Model
{
public $table = 'product';
protected $perPage = 8;
}
/* End of file Home_model.php */
And here is in my core folder, because i made a custom configuration like this :
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class My_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
$model = strtolower(get_class($this));
if (file_exists(APPPATH . 'models/' . $model . '_model.php')) {
$this->load->model($model . '_model', $model, true);
}
}
// Load view with Default Layouts
public function view($data)
{
$this->load->view('layouts/app', $data);
}
}
If I'm running the program in my localhost, it's totally fine and works. Why do I get this error on a production server?
From the error message you received, the important part is
Message: Call to a member function select() on null
which means your model was not loaded!
as your code works on your localhost environment, but not on the production server, most likely the error is caused by applying wrong Naming Conventions:
File names must be capitalized. For example: Myclass.php Class
declarations must be capitalized. For example: class Myclass Class
names and file names must match.
public function __construct(){
parent::__construct()
}
add this to your Home controller
I have an error with the following file, and specifically, I assume, the following line:
$data['events'] = $this->homes->get_events();
The error is:
Message: Undefined property: CI_Loader::$homes
I am in the controller file, where I assume the problem is.
File name: /application/controllers/Home.php
$data['events'] = $this->homes->get_events(); <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function _construct()
{
parent::_construct();
$this->load->model('homes');
}
public function index()
{
$data['events'] = $this->homes->get_events();
$this->load->view('template/header.php');
$this->load->view('home/index.php', $data);
$this->load->view('template/footer.php');
}
}
There is a model file at models/Homes
We tried changing the name of the model file to 'homes' (lower case) and also the code to 'Homes', but the same error persisted.
Specifically the error on running the url is:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$homes
Filename: controllers/Home.php
Line Number: 15
Backtrace:
File: public_html/anchor/application/controllers/Home.php
Line: 15
Function: _error_handler
File: /public_html/anchor/index.php
Line: 315
Function: require_once
<?php
session_start();
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class View_job extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('Userdb', '', TRUE);
$this->load->model('Locationdb');
$this->load->model('All_functiondb');
$this->load->library('form_validation');
}
}
///
A PHP Error was encountered Severity: Notice
Message: Undefined property: Indexpg::$session
Filename: php_include/authenticate.php
Line Number: 3
Fatal error: Call to a member function userdata() on null in
C:\xampp\htdocs\CodeIgniter-job-site-master\hindusthanjobs\application_candidate_6423\php_include\authenticate.php
on line 3
define session after tis line
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
first thing is that check is session library is loded in controller.
public function __construct()
{
parent::__construct();
$this->load->library('session');
}
So, I'm developing a website in Codeigniter 3 with HMVC, and I've got the following folder structture inside my application folder:
core
MY_Controller.php
modules
login
controllers
Keep_Logged.php
Login.php
So, this is the MY_Controller (I'm using it as parent for all controllers):
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
class MY_Controller extends MX_Controller {
function __construct() {
parent::__construct();
$this->load->module("template");
$this->load->module("login/Keep_Logged");
$this->Keep_Logged->cookie_authenticate();
$exceptions = array("login", "login/authenticate");
if ($this->session->user_id == NULL && !in_array(uri_string(), $exceptions)) {
redirect("/login", "refresh");
}
}
}
And this is the Keep_Logged.php
<?php
class Keep_Logged extends MY_Controller
{
function __construct() {
parent::__construct();
$this->load->model("login/Login_Model");
$this->load->helper("cookie");
}
function cookie_authenticate() {
if ($user = $this->Login_Model->check_login(get_cookie("user_email"), get_cookie("user_password"), TRUE)) {
$this->session->set_userdata(array(
"user_id" => $user->user_id,
"user_email" => $user->email,
"user_name" => $user->name,
"user_kind" => $user->kind
));
}
}
}
My problem is I can't load the Keep_Logged.php controller, though I can load the Login.php normally (Or any another controller with the same name as it's module). How can I fix this ? I get this errors every time.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI::$Keep_Logged
Filename: MX/Controller.php
Line Number: 59
-
An uncaught Exception was encountered
Type: Error
Message: Call to a member function cookie_authenticate() on null
Filename: D:\xampp\htdocs\CIHMVC\application\core\MY_Controller.php
Line Number: 13
You try to call method of child class in parent class. Move cookie_authenticate() method to MY_Controller and call in as $this->cookie_authenticate(). Don`t forget to move staff from Keep_Logged constructor to MY_Controller constructor.
I have a CodeIgniter spark defining&autoloading a class libraries/Nci_nicecontroller.php:
class Nci_nicecontroller extends CI_Controller {
//...
}
//autoloaded using $autoload['libraries'][]='nci_nicecontroller';
now I want to use Nci_nicecontroller in my application's controller, e.g.:
class Welcome extends Nci_nicecontroller {
//...
}
//autoloaded using $autoload['sparks'][]='nci-extensions/0.0.4';
obviously, I can't just $this->load->spark in my controller's constructor, because it's required on class extension.
when not using sparks, I just put the Nci_nicecontroller in a core/MY_Controller.php, but with sparks, this won't work.
I tried autoloading the spark in my application, which didn't work.
Then I tried:
get_instance()->load->spark('nci-extensions/0.0.4');
in the header of controllers/welcome.php, which gives me following errors:
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/welcome.php
Line Number: 2
--and--
Fatal error: Call to a member function spark() on a non-object in
C:\xampp\htdocs\CodeIgniter_demo\application\controllers\welcome.php on line 2
what shall I do?
Try to do something like that:
class Wellcome extends CI_Controller {
protected static $_nci = null;
public function __construct(){
parent::__construct();
$this->_nci = $this->load->spark('nci-extensions/0.0.4');
}
public function index(){
$result = $this->_nci->getSomething();
echo $result;
}
}