Codeigniter Model extending - Fatal error: Class 'MY_Basedbclass' not found in - php

I know there are other similar questions, but even after following all the syntax, this errror exists
I am using Codeigniter version 2.1.4 on wamp server, windows 7.
in application/core/ i have MY_Basedbclass.php starting with
abstract class MY_Basedbclass extends CI_Model
{
and trying to use it in my mode like
class Accounts_manager extends MY_Basedbclass
{
ending up with the error - Fatal error: Class 'MY_Basedbclass' not found in C:\wamp\www\party_app\server\application\models\accounts_manager.php
Please suggest what i am doing wrong. Thanks
EDIT - Addign a screen shot for the file structure sake

why you define your core model class as abstract class? after that you can only set core model class as MY_Model. this name get from subclass_prefix + class_name_you_want_to_over_write
define your core class like this:
class MY_Model extends CI_Model {
// your code
}
before that assured in your config.php file you set $config['subclass_prefix'] = to MY_
config file address: application > config > config.php

Related

CodeIgniter Fatal error: Class on CORE controller

I have created under application/core folder a file called Auth_controller.php.
I am using CodeIgniter 3.
php 5.3.3
Centos 6.9
The content is
class Auth_Controller extends CI_Controller{
in config file i declare
$config['subclass_prefix'] = 'Auth_';
Then finally when i called it...
class Home extends Auth_Controller {
it gives me a
Fatal error: Class 'Auth_Controller' not found in /var/www/html/calllist/application/controllers/Home.php on line 3
Message: Class 'Auth_Controller' not found
You using $config['subclass_prefix'] = 'Auth_'; settings means you want to extend core CI classes.
If you want to extend CI_Controller then you class name should be Auth_Controller if you want to extend model your class name should be 'Auth_Model'
But Remember those classes/files should be inside your application\core folder
For more details please look at CI documentation
The location of Auth_Controller must be in application\core directory. Otherwise you need to manually include class to your controller file.
You need to include Auth_Controller like below mentioned code.
<?php
require_once("secure_area.php");
class Reports extends Secure_area {

Fatal error: Class not found in codeigniter

I have created a model Admin_Model under Application\core directory of code igniter. I put all basic database operations under it. When I try to extend my models who are under Application\model directory, it throws error.
Fatal error: Class 'Admin_Model' not found in <path to root>/application/models/new_model.php on line 3
Should I miss any configuration?
Thanks all for your efforts.
I find a solution.
By default CodeIgniter have a setting in its config file.
$config['subclass_prefix'] = 'MY_';
I just replace 'MY_' with 'Admin_' everything works fine.
$config['subclass_prefix'] = 'Admin_';
More appropriate solution is
Put class file in libraries folder
Add following code to config.php
function __autoload($classname)
{
if(strpos($classname,'CI_') == 0)
{
$file = APPPATH.'libraries/'.$classname.'.php';
if(file_exists($file))
{
#include_once($file);
}
}
}
That's All
This may also be helpful, if you still have problems with __autoload to use class from libraries. it's work for me, when I use class library tobe parent class at controller.
PHP 5 >= 5.1.2, PHP 7
this is mycode at application/config.php
spl_autoload_register(function ($classname){
if(strpos($classname,'CI_') == 0){
$file = APPPATH.'libraries/'.$classname.'.php';
if(file_exists($file)){
#include_once($file);
}
}
});
Extending Core Class
If all you need to do is add some functionality to an existing library - perhaps add a function or two - then it's overkill to replace the entire library with your version. In this case it's better to simply extend the class. Extending a class is nearly identical to replacing a class with a couple exceptions:
The class declaration must extend the parent class.
Your new class name and filename must be prefixed with MY_ (this item is configurable. See below.).
For example, to extend the native Model class you'll create a file named application/core/MY_Model.php, and declare your class with:
class MY_Model extends CI_Model {
}
Note: If you need to use a constructor in your class make sure you extend the parent constructor:
class MY_Model extends CI_Model {
function __construct()
{
parent::__construct();
}
}
I setup my environment on a Windows machine. Then after move to production using Ubuntu, I had the class not found error.
I discovered my files extension were PHP (capital letter). Linux is case sensitive, so the file name need to be lowercase php.

parent controll in Codeigniter 2.2 project not found

In my CI 2.2 project I want to make my parent controll with app's common functionality for use in all app and for this I create file :
application/libraries/N_Controller.php :
<?php
class N_Controller extends Controller
{
public function __construct()
{
parent::__construct();
}
But on first attempt to use it in file
application/controllers/admin/admin.php
<?php
class Admin extends N_Controller
{
public function __construct()
{
parent::__construct();
I got error:
PHP Fatal error: Class 'N_Controller' not found in /controllers/admin/admin.php on line 3, referer: http://local-ci22.com/admin/hostel/edit/15
I tried to add in application/config/autoload.php file :
$autoload['libraries'] = array( 'AppSmarty', 'AppUtils', 'N_Controller');
But it did not help. Which is the correct way ?
if you want to extend the functionality of a system class. you need to follow this recomendations.
place your extended class in /application/core, be sure that you name it exactly like the name and casing of the class created.
your class should extend from CI_Model or CI_Controller, depending on your needs.
wherever you implement your new class, be sure that you honor the same name casing from your extended class.
you should have configured the $config['subclass_prefix'] on /application/config/config.php. let's say in your case with the value 'N_'
what i can see from your code, you are not extending from CI_Controller and your path seems wrong.
Informative note: the /application/library is used to place classes and libraries from 3rd parties that won't fit into CI schemas.

Can't auto load the files in core directory

I can't figure out what I'm doing wrong. In the core directory of my app I have two files CMController.php and CMBase.php.
CMBase.php
class CMBase extends CI_Controller {}
CMController.php
CMController extends CMBase {}
Then in random controller
class RandomController extends CMController {}
And I get
Fatal error: Class 'CMBase' not found
subclass_prefix in the config is set to CM.
If I do require_once 'CMBase.php' in CMController file it works fine.
So my question is why the file CMBase is not loaded automaticly?
When you are extending the core controller your class name needs to end with "Controller". So you can't name your class CMBase it would have to be CMBase_Controller.
So if the value in $config['subclass_prefix'] is "CM" you class needs to look like
class CMController extends CI_Controller {//...}
Then once you have done that you can do
class AnyClassName extends CMController {//...}
Have you tried looking $config['subclass_prefix'] = 'MY_'; applications folder. Can only extend MY_Controller etc. http://ellislab.com/codeigniter/user-guide/general/controllers.html
https://github.com/EllisLab/CodeIgniter/wiki/MY-Controller
I think your missing the _ underscore part ie MY_

Zend Framework can't find Model

I have a model, Application_Model_DbTable_Login, located in Application > models > DbTable > Application_Model_DbTable_Login.php.
In my controller, LoginController, I am trying to instantiate the Model, but it's saying that it can't find it. Here is the exact error: Fatal error: Class 'Application_Model_DbTable_Login' not found in /usr/local/zend/apache2/htdocs/AssetLibrary/application/controllers/LoginController.php on line 8.
I just started working with Zend Framework. Thanks for any help.
Rename the file
Application_Model_DbTable_Login.php to Login.php
and ensure the class within is defined as
<?php
class Model_DbTable_Login extends Zend_Db_Table_Abstract
{}
Then in your controller call
$model = new Model_DbTable_Login();

Categories