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


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(
       $this->id $id;
       $this->userId $userId;
       $this->iban $iban;
       $this->bic $bic;

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


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.

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:

$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.



thanks for the answer Smile

PHP Code:

was excactly what iam looking for Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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