Getting Started with Kohana

jsandahl

So you’ve read my Model-View-Controller article from last week and now you’re ready to get started working with Kohana, the best open-source, lightweight MVC out there for PHP.

I’ve simplified the process I use for your purposes.

1. Go get Kohana from their website: http://kohanaframework.org/download

2. Empty the folder into the site root where you wish to install Kohana.

3. Make sure you have your server configured and then navigate to the root of your server in your browser.

4. You might get various installation errors. There is enough documentation that you can Google the error and come up with a solution rather quickly.

When I last installed it, I got an error that $salt was not set. Salt is used to hash passwords for secure encryption. If you get this error, open up your bootstrap.php and add this line somewhere:

Cookie::$salt = '';

5. In case you haven’t located the bootstrap by now, it’s located in the /application folder, just sitting there all alone with no other php-file friends. That’s ok. Bootstrap is where everything ties together.

6. Enter your bootstrap and uncomment the modules near the bottom which you intend on using for your application. These can always be unlocked later as well. You will nearly always need Auth, Cache, Database, and ORM modules. You may choose to install a kohana-email module, but more on that in a separate post.

7. If your application uses a database (why wouldn’t it?) then you will need to configure your database in /modules/database/config/database.php. Make sure you give the localhost address to the database if your database is hosted locally.

When you’ve configured the database, you’re set. The next steps you’ll take might be:

1. Make CSS and JS folders in the /application folder.

2. Set custom routing for your pages. This might take some time to wrap your head around. For the beginning, just know that your default URL scheme is going to be <controller>/<action>/<id>, where the controller name is the name of the class within the controller, not the file name. The action will be whatever action you have set, such as action_index(). And if you need to pass a single variable, this will be in the place of the id.

To access this variable, use this simple piece of code:

$this->request->post('<variable>');

3. Begin adding files to the folders. Put your views in /application/views. Put your controllers in /application/classes/controller. And your models go in /application/classes/model.

Your next steps will be to study up on how the ORM factory works to bind the Model-View-Controller together. This should at least get you started.

3 thoughts on "Getting Started with Kohana"

  1. glass dildo says:

    we prefer to honor several other world-wide-web web sites around the net, even when they arent linked to us, by linking to them. Under are some webpages really worth checking out

  2. always a significant fan of linking to bloggers that I enjoy but dont get quite a bit of link adore from

  3. usually posts some extremely interesting stuff like this. If youre new to this site

What Are Your Thoughts?

Your email address will not be published. Required fields are marked *