Daniel Sorichetti
Daniel Sorichetti

Reputation: 1951

Using custom classes in Kohana 3

Hey, I'm creating a Call of duty 4 Server Watcher in Kohana 3, and I had created the basic classes for it before:

  1. A static Socket class (for handling basic network commands)
  2. A Cod4Socket class, (which uses the previously mentioned Socket class) that provides wrapper functions for basic commands.

What I want is to be able to use said classes inside the controllers for the website.

Where am I supposed to put the class files, where should I "include" them, and how do I use them?

Edit: I'm using Kohana 3.

Upvotes: 0

Views: 2787

Answers (3)

Alex Coroza
Alex Coroza

Reputation: 1757

Additional Info:

Sometimes, you want to place your custom classes in a place like this

application/
    classes/
        controllers/
            .......
        models/
            ......
        etc/
            CustomClassFirst.php
            CustomClassSecond.php

You can call these classes by

$customClassOne = new Etc_CustomClassFirst();

and then redefine the class name into this

class Etc_CustomeClassFirst {}

Upvotes: 0

Lethargy
Lethargy

Reputation: 1889

Where am I supposed to put the class files?

Add your class files into the application/classes/ directory with lowercase filenames.

  • Socket should go into application/classes/socket.php
  • Cod4Socket should go into application/classes/cod4socket.php

Where should I "include" them, and how do I use them?

There is no need to manually include them; simply use them as if they were already included. The Kohana autoloader will find the classes if they're in the right files.

Upvotes: 5

Daniel Sorichetti
Daniel Sorichetti

Reputation: 1951

Did it on my own: http://www.dealtaker.com/blog/2010/06/02/kohana-php-3-0-ko3-tutorial-part-9/

You have to include the files in the bootstrap.php file, and then just call it normally on your controller.

Upvotes: -3

Related Questions