0

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 .

user2065593
  • 123
  • 1
  • 2
  • 11

1 Answers1

0

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 called Student.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.

$this->load->library('students');

THen your will be able to use your method as such

$this->students->method_name();

Make sure you load the library manually as mentioned above autoload.

Malachi
  • 33,142
  • 18
  • 63
  • 96
  • I am working on Windows, but where do I have to put "Students.php"? Because I want to do something like this: while(something){ $arr[] = new Student(); } return arr; – user2065593 Feb 12 '13 at 17:56
  • What is 'Students' Does it hold business logic? e.g. is it a model - http://ellislab.com/codeigniter/user-guide/general/models.html – Malachi Feb 12 '13 at 17:59
  • No, only getters and setters. But I want to use it in my models and controllers – user2065593 Feb 12 '13 at 18:03
  • Yes, I did it before, but in that case I can not do an array of Students – user2065593 Feb 12 '13 at 18:44
  • Would you be able to post the contents of your students.php file so that I can see what it contains to try and diagnose your problem? try uploading to pastebin – Malachi Feb 12 '13 at 20:27
  • Thanks, I just put it on libraries – user2065593 Jun 21 '13 at 04:08