Welcome Guest, Not a member yet? Register   Sign In
Custom libraries and directory structure help
#1

[eluser]sailorob[/eluser]
I'd like to create my own boilerplate-esque classes and keep them nested cleanly within the directory structure.

For instance:
Quote:/libraries/Collection.php (base methods for a collection of items)
/libraries/Item.php (base methods for items)
/libraries/projects/Collection.php (extends ../Collection.php adding methods and whathaveyou)
/libraries/projects/Item.php (extends ../Items.php)
/libraries/users/Collection.php
/libraries/users/Item.php

I'm having rough go figuring out if I need the prefix "MY_" (or whatever I've configured it to), and if it's needed on both the class name, and file name for base classes. I am not extending CI's models as of now, just my own as seen above.

I can get the base classes to work, but not the extended classes. I don't think it's finding my base classes when I try to extend them. Are the sub-directories causing the issues? I am initializing like so:
Code:
$this->load->library('projects/Collection');

/libraries/Collection.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Collection {

    protected $ids = NULL;

    function __construct()
    {
        return $this;
    }

    public function load()...

/libraries/projects/Collection.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Collection extends Collection {

    function __construct()
    {
parent::__construct();
return $this;
    }

}

Or am I trying to make CI do something it's not supposed to do?
#2

[eluser]InsiteFX[/eluser]
The classes you are trying to extend should all be in the same directory.

Also you cannot have to classes with the same name!
#3

[eluser]PhilTem[/eluser]
@InsiteFX is right: Two or more classes cannot have the same name. So basically, you're not making CI do something it's not supposed to do, you're making PHP do something it's not supposed to do Wink




Theme © iAndrew 2016 - Forum software by © MyBB