Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter libraries - Error loading custom classes
    primarykey
    data
    text
    <p>I am unable to load my custom class which <strong>doesnot</strong> extend from any core class. I have placed my custom class in a subfolder inside application/libraries.</p> <p>So here is my folder structure</p> <pre><code>application |_ libraries |_ cgh |_ cgh_asset.php |_ cgh_article.php |_ cgh_asettype.php |_ controllers |_ welcome.php </code></pre> <p>Class Cgh_article is a subclass of Cgh_asset</p> <p>Cgh_asset.php :</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); abstract class Cgh_asset { public $id; public $type; public $title; public $content; public $user; abstract public function generate_url(); function __construct() { $this-&gt;generate_url(); } } ?&gt; </code></pre> <p>Cgh_article.php :</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Cgh_article extends Cgh_asset { function __construct() { parent::__construct(); $this-&gt;type=Cgh_assettype::article; } function generate_url() { $this-&gt;url="Article_URL"; } } ?&gt; </code></pre> <p>Cgh_assettype.php:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Cgh_assettype { const type1="type1"; const type2="type2"; const article="article"; } ?&gt; </code></pre> <p>Controller welcome.php</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { public function index() { $this-&gt;load-&gt;library('cgh/Cgh_assettype','cgh/Cgh_asset','cgh/Cgh_article'); $this-&gt;load-&gt;view('welcome_message'); } } </code></pre> <p>The error I get is : Unable to load the requested class: Cgh_assettype</p> <p>I must have tried all possible upper and lower case combinations of classnames, filenames, but the error is always the same.</p> <hr> <p>After going through some answers, I think probably I should add one basic question here - Is it at all possible to have my own custom object types within codeigniter ... types that should be quite obvious from my question ?</p> <hr> <p>This seems to work for me, so here is what I will be doing ... at least till something breaks :</p> <p>In the constructor of my controller, I use require_once for my classes ... and good thing is I can combine all my classes into a single file -- my classes initially were in a single file anyways --This is my controller after the changes, and this works :</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { public $cgh_assettype; public $cgh_asset; public $cgh_article; function __construct() { parent::__construct(); //$this-&gt;load-&gt;library(array('cgh/cgh_assettype','cgh/cgh_asset','cgh/cgh_article')); echo "Including CGH&lt;br /&gt;"; echo "&lt;p&gt;Apppath is ". APPPATH. "&lt;/p&gt;"; require_once(APPPATH.'libraries/cgh/Cgh_assettype.php'); require_once(APPPATH.'libraries/cgh/Cgh_asset.php'); require_once(APPPATH.'libraries/cgh/Cgh_article.php'); } public function index() { $iCgh_article=new Cgh_article(); echo "&lt;p&gt;$iCgh_article-&gt;url&lt;/p&gt;"; $this-&gt;load-&gt;view('welcome_message'); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload