Welcome Guest, Not a member yet? Register   Sign In
problem loading custom class
#1

[eluser]Unknown[/eluser]
Hi,
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


Class Cgh_article is a subclass of Cgh_asset
Cgh_asset.php :

Code:
<?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 :

Code:
<?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:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cgh_assettype
{
    const question="question";
    const answer="answer";
    const article="article";
}

?>

Controller welcome.php

Code:
<?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 getis :
Unable to load the requested class: Cgh_assettype

I must have tried all possible upper and lower case combinations of classnames, filenames, but the error is always the same. Searched a lot on ci and google, but couldnt really find a solution. Could any of the gurus here help me please?

Thanks
Sindhu




Theme © iAndrew 2016 - Forum software by © MyBB