我無法裝入我的自定義類亙古不變的從任何核心類擴展。 我已經把我的自定義類裏面的應用程序/庫的子文件夾。笨庫 - 錯誤加載自定義類
因此,這裏是我的文件夾結構
application
|_ libraries
|_ cgh
|_ cgh_asset.php
|_ cgh_article.php
|_ cgh_asettype.php
|_ controllers
|_ welcome.php
類Cgh_article是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";
}
?>
控制器的welcome.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');
}
}
我得到的錯誤是: 無法加載所請求的類:Cgh_assettype
我一定已經嘗試了所有可能的上,下類名,文件名,但錯誤的情況下組合是永遠不變的。
通過一些答案去後,我想可能是我應該在這裏增加一個基本問題 - 它是在所有可能笨內有我自己的自定義對象類型...類型,應該是相當明顯的,從我的問題?
這似乎爲我工作,所以這裏是我會做......至少到一些突破:
在我的控制器的構造函數中,我使用require_once我的班.. 。而好消息是,我可以我所有的類合併成一個單一的文件 - 我的班最初是在一個單一的文件反正 - 這是在變動後我的控制器,這一點也適用:
<?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');
}
}
您是否嘗試過使用低級文件名並加載**數組庫**; '$這 - >負載>庫(陣列( 'CGH/cgh_assettype', 'CGH/cgh_asset', 'CGH/cgh_article'));'? –
我已經嘗試過所有可能的組合類名,文件名的大寫和小寫。沒有工作。我試過從類名,文件名中刪除Cgh_前綴。沒有工作。我嘗試將我的類文件移動到應用程序/庫的根目錄中。沒有工作。目前我正在嘗試require_once(APPPATH.'libraries/cgh/Cgh_assettype.php');在index.php – SIndhu
順便說一句,你正在嘗試加載'cgh_assettype',但你的文件被命名爲'cgh_asettype.php',你檢查了嗎? –