this is a very basic question regarding to Codeigniter. I was reading official documentation of Codeigniter from their website regarding to Model, library and etc folder purposes and usage. However, it still confuses me when to use each one of them. What is difference between library and helper? It would be great if someone can provide me a web link or clear definition for each of them and usage example.
Furthermore, I wanted to create a simple library class for testing and under library folder so I have created
Test.php file and it contains
<?php
class Core{
public function __constructor(){
echo 'worked';
}
public function test(){
return 'Test function';
}
}
In my controller, I’m trying to call this using
$this->load->library(‘core’); but it does not work. Also, how do you call test() function from the Core library?
Thanks in advance,
Model objects are the parts of the application that implement the domain logic, also known as business logic. Commonly used to interface with your database.
Libraries are classes that can be used in your application.
Helpers are more like standalone functions that can be implemented.
Regarding your use of libraries.
Libraries in CI have the same file name as the class, so either rename you file to core.php or change the name of your class to Test.
Once you have loaded the library (either directly or using autoload – found in config folder), it gets added to the CI super oject. You can then access it like; $this->core->test();
N.B. I’m not sure if core is a safe name for use in Codeigniter.