English 中文(简体)
校准图书馆——装饰习惯班
原标题:Codeigniter libraries - Error loading custom classes

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 );
    }
}
问题回答

You need to call $this->load->library for each library.

$this->load->library( cgh/Cgh_assettype );
$this->load->library( cgh/Cgh_asset );
$this->load->library( cgh/Cgh_article );

http://codeigniter.com/user_guide/libraries/loader.html>rel=“nofollow”>$this->load->library 参数3。

  1. File to load
  2. (optional) $config array
  3. (optional) String to rename library to ($this->Renamed_library)

如果你想要把多个图书馆装上一条线,则使用一个阵列作为第一个参数。

$this->load->library(array( cgh/Cgh_assettype , cgh/Cgh_asset , cgh/Cgh_article ));

你们的图书馆档案名称是否资本化? (Your 提交的复数结构说不是)。

我不知道分局内有图书馆,但我知道档案需要资本化。

rel=“nofollow”http://codeigniter.com/user_guide/general/creating_libraries.html

签署公约

  • 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.

你们应当装上图书馆,或者只装一次。 如果你第二次重装,你就错了。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签