Aspen:Creating Custom Classes
From Aspen Documentation
Aspen provides a way for you to create your own system classes. If you want to keep them in the system folder, you may simply use:
$config['load_add_core_class'][] = array('classname' => 'Myclass');
Or, you can also use the custom_classes configuration:
$config['custom_classes'][] = array('classname' => 'Myclass', 'root'=>MODULES_PATH.DIRECTORY_SEPARATOR.'Index');
You can store your class files anywhere you like, but for this example we'll store it within the Index module, for demonstration purposes.
First, we need to create a file in modules/Index/myclass/myclass.php.
<?php class Myclass { /** * @var object $APP Holds our original application * @access private */ private $APP; public function __construct(){ $this->APP = get_instance(); } public function testMe(){ print 'Myclass works!<br>'; } } ?>
Then, we need to activate this class in our configuration file. You may user either the config.php are the app.default.config.php files.
$config['custom_classes'][] = array('classname' => 'Myclass', 'root'=>MODULES_PATH.DIRECTORY_SEPARATOR.'Index');
The root index of the array passes the root file system path the library can use to locate the file.
After activation and loading, you may access the new class.
For example, to access the testMe function from our child class, we could do so by:
$this->APP->myclass->testMe();