Creating Libraries

When we use the term “Libraries” we are normally referring to the classes that are located in the libraries directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create your own libraries within your libraries directory in order to maintain separation between your local resources and the global framework resources.

Storage

Your library classes should be placed within your libraries directory, as this is where Codingox will look for them when they are initialized.

Naming Conventions

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

The Class File

Classes should have this basic prototype:

<?php
defined('APP_PATH') OR exit('No direct script access allowed');

class Someclass {

        public function some_method()
        {
        }
}

Note

We are using the name Someclass purely as an example.

Using Your Class

From within any of your Controller methods you can initialize your class using the standard:

$this->library('someclass');

Where someclass is the file name, without the “.php” file extension.

Once loaded you can access your class using the lower case version:

$this->someclass->some_method();  // Object instances will always be lower case