tags:

views:

195

answers:

4

straight to the point :

I am using Kohana, and I am looking at another script written in plain PHP. In the script, I have a class ShoppingCart. If I am to convert the script to Kohana, where am I to put the class, its methods and its properties?

Is it in my existing default controller? Or should I put it in a separate controller? Or as noobie as it may sound, will I put it in the model?

A: 

That depends on the specifics of the class I suppose. To be honest I don't know anything about Kohana, but there's probably a place for "vendor files" somewhere. Maybe it's best to place it there and write wrapper functions for it in your controller. If the class already integrates well with Kohana you may instead choose to use it as a controller or model directly. Or you might want to take the time to rewrite it to make it work as a controller...

Only you can evaluate the best place for it, there's no hard and fast rule here.

deceze
A: 

Kohana has a folder for 3rd party libraries. The main one is under system/vendor, you can put it in you application/ as well.

Many PHP class loaders require details like your filename should be the same as the class name (at least that's what I read in the Kohana documentation) if you want the classes to be automatically loaded.

Daff
A: 

If you need to use 3rd party code in your app it's recommended that you create a folder in your app / module folder called 'vendor' and place all of that code there.

You can then include the files by calling:

include kohana::find_file('vendor', 'filename');

If needs be you can also create a wrapper for the external library, a good example of this is the email helper which uses the 3rd party Swift email library.

If you're porting your own class to kohana then you need to work out what the class will be doing and categorise it accordingly.

If the class will be fetching items from some kind of database then you should make it a model. Libraries are usually sets of code that you want reuse across controllers / models, such as authentication, calendar generation etc. Controllers are used for passing data from models to your views / libraries.

See the docs for more info

Matt
A: 

As per kohana convention, you should place custom classes in application/libraries folder. However for this, you need to know how to get the class to work after putting it there. If you can't figure that out, you can do anything like putting it in your controller or making another controller of it, etc.

Sarfraz