I am unable to load my custom class which doesnot extend from any core class. I have placed my custom class in a subfolder inside application/libraries.
So here is my folder structure
application
|_ libraries
|_ cgh
|_ cgh_asset.php
|_ cgh_article.php
|_ cgh_asettype.php
|_ controllers
|_ welcome.php
Cgh_article is a subclass of Cgh_asset
Cgh_asset.php :
<?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->generate_url();
}
}
?>
Cgh_article.php :
<?php
if ( ! defined( BASEPATH )) exit( No direct script access allowed );
class Cgh_article extends Cgh_asset
{
function __construct()
{
parent::__construct();
$this->type=Cgh_assettype::article;
}
function generate_url()
{
$this->url="Article_URL";
}
}
?>
Cgh_assettype.php:
<?php if ( ! defined( BASEPATH )) exit( No direct script access allowed );
class Cgh_assettype
{
const type1="type1";
const type2="type2";
const article="article";
}
?>
主计长欢迎.php
<?php if ( ! defined( BASEPATH )) exit( No direct script access allowed );
class Welcome extends CI_Controller {
public function index()
{
$this->load->library( cgh/Cgh_assettype , cgh/Cgh_asset , cgh/Cgh_article );
$this->load->view( welcome_message );
}
}
The error I get is : Unable to load the requested class: Cgh_assettype
我必须尝试所有可能的上下级案件组合,这些类别的名称、档案名称,但错误总是一样的。
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 ?
在我看来,这似乎对我来说是可行的。
在我的控制师的构造中,我需要——我的班级......好事是,我可以把我的班子合并为一个单一档案——我的班子最初是一只手脚。 ——这是我经过修改后的控制者,这项工作:
<?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->load->library(array( cgh/cgh_assettype , cgh/cgh_asset , cgh/cgh_article ));
echo "Including CGH<br />";
echo "<p>Apppath is ". APPPATH. "</p>";
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 "<p>$iCgh_article->url</p>";
$this->load->view( welcome_message );
}
}