I have some problems to use my own classes using codeigniter. If it is not an error, it always says that the class can not be loaded.
For example, I created a class “Student” with atributes and only getter and setter methods, so I need to use that class in a model to return an array of “Students”(what I can not do with “load->library”) or to receive a “Student” for storing it, and I also need that class for my controller to do something with “Student”
I am working in Windows and I don’t want to use an ORM because de app is not big.
I also want to do something like this in my model:
while(something){
$arr[] = new Student();
}
return $arr;
What can I do? I will be grateful for your answers.
(PD: I’m sorry, I am not an English speaker)
I solved it
The only thing I had to do was create the file Student.php (where the class Student is) and put it on Libraries, after that:
$this->upload->library("Student.php");
and after that we can “instanciar” the class .
What operating system are you developing on?
On Unix based operating systems the file system is case sensitive so make sure that when your calling the library for example as:
$this->load->library('student');that the file on the disk is calledStudent.php. On Windows however the file system is case insensitive so this is not really an issue.For more information you should read:
Case sensitive file names in Linux and not in Windows
UPDATE
From your comments it should like you wish to use your class like a library in which case you should include the file in the ‘libraries’ directory and load the library which is outlined in the documentation.
THen your will be able to use your method as such
Make sure you load the library manually as mentioned above autoload.