• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Integrate my Classes into CodeIgniter

#1
Hello,

Iam new in the "Codeigniter World".

Im still working at my first "real" Project with CodeIgniter and I Like to add some "Entity" Classes for my Project.
But Iam not sure whats the right way to do that in CodeIgniter.

Here is a Sample Class:
PHP Code:
class UserPayment {

 
   /**
     * @var $id int
     */
 
   private $id;

 
   /**
     * @var $userId int
     */
 
   private $userId;

 
   /**
     * @var $iban String
     */
 
   private $iban;

 
   /**
     * @var $bic String
     */
 
   private $bic;

 
   function __construct(
 
       $id,
 
       $userId,
 
       $iban,
 
       $bic
    
)
 
   {
 
       $this->id $id;
 
       $this->userId $userId;
 
       $this->iban $iban;
 
       $this->bic $bic;
 
   }



I hope you know what I mean.
Sorry for my English Wink

Greats!
Reply

#2
If I understand you correctly. Straight up PHP classes are considered CodeIgniter Libraries. So you can just throw it into the lib's folder and call it like this in your controller.
$this->load->library('classname');

Then access it with

$this->classname->foo('hello world');

A few things to note here thou.
#1. the class name and the filename are the same
#2. You get back a singleton.

If you need to just load the class you can use:

$this->load->file('library/classname');
$a = new classname();
$b = new classname();

(If I recall)

If it's something that is accessing a "model" yes you should break it out into a "correct" MVC model but, more than likely it's just easier if it's 3rd party code to keep it all together like a "black box object". Sometime's if it needs multiple additional files I place them in folder in library and create a wrapper in the root level to set it up or just call it in it's folder.

Hopefully that's enough to get to headed in the right direction. Here is the manual page.

http://www.codeigniter.com/user_guide/li...oader.html
Reply

#3
Hi,

thanks for the answer Smile

PHP Code:
$this->load->file('library/classname'); 

was excactly what iam looking for Smile

Greats
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.