KOHANA
Kohana is a PHP framework that follows MVC architecture (Recently it’s based on HMVC Architecture).
What is MVC ARchitecture?
M-Model–>objects–these objects encapsulate data–dbms
V-View–>presentation–what the user sees–css, html, javascript.
C-Controller–>link between model and view–respond to events by the user (user-interaction) and invoke changes in the model and view based on that.This consists of routers which map certain piece of code to certain url.
In basic web architecture, browser interacts pages and these pages might contain lump sum amount of code on doing something and giving the output for us and even fetching things from database. So , instead of having one-page with all the code it in we can organize this in a better way by breaking into parts which can be done by using MVC architecture ..tadaaaaaa!!!!
So, now our browser interacts with the controller and controller decides on what to do based on the request sent by the browser. If any data has to be fetched or anything has to be done on data then the controller interacts with the model and all the code for getting the data or manipulation of data or connecting to the database is all put in the model. Once the model’s done with its work it sends back the data to the controller and the the controller sends it back to the View and the view returns what kind of html, css , javascript has to be returned to the browser.So the server puts together all the content (data) and formats it into a template and sends it to the user.
MVC is popular as it isolates the application logic from the user interface layer and supports separation of concerns.200px-mvc-process-svg
Kohana installation on Ubuntu 15.04:
Terminal:
To download kohana:
wget https://github.com/kohana/kohana/releases/download/v3.3.6/kohana-v3.3.6.zip
Unzip:
aptitude install -y unzip
unzip kohana-v3.3.6.zip
Create a new directory(MyDemo):
mkdir /var/www/html/MyDemo
Copy the contents in kohana to MyDemo:
cp -r kohana-v3.3.6/* /var/www/html/MyDemo
The installation’s subdirs may have lost their permissions during zip extraction so Chmod them all to 755 by running :
find . -type d -exec chmod 755 {} \;
http://www.computerhope.com/unix/uchmod.htm (on chmod)
Move to MyDemo dir:
cd /var/www/html/MyDemo/
Set permissions
find . -type d -exec chmod 755 {} \;
After installing Kohana, you need to setup virtual host and add it to DNS:
sudo a2enmod rewrite a2enmod headers
Setting up virtual host:
sudo gedit /etc/apache2/sites-available/000-default.conf
Here, Enter this before vm and save it:
<VirtualHost *:80>
ServerAdmin mydemo.com
DocumentRoot “/var/www/html/MyDemo/”
<Directory “/var/www/html/MyDemo/”>
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
ServerName mydemo.com
ErrorLog “/var/log/apache2/error.log”
</VirtualHost>
Add this virtual host to DNS:
sudo nano /etc/hosts
Add this:
127.0.0.1 mydemo
and save it.
Now run your server:
sudo service apache2 restart
When you do the environment test, you might get some permission error in cache and log directory. For this:
(assuming you are in MyDemo Directory)
chmod a+x application/logs/ application/cache/
(or)
chmod a+w application/logs/ application/cache/
Now remove or move install.php
In application/bootstrap.php
change the time zone and go to
Kohana::init(array(
‘base_url’ => ‘/kohana/’,
));
and change this to:
Kohana::init(array(
‘base_url’ => ‘/MyDemo/’,
));
So, by default it goes to the Welocome controller and to the page index.
This means there is a class named Welcome with function index.
mydemo.com/index.php/welcome
You can take parameters too:
You can see in your bootstrap.php that (<controller>(/<action>(/<id>)))’) This means that anything after action is a parameter which is named as id
Lets write a route to fetch these parameters:
public function action_fetchid(){
$a=$this->request->param(‘id’);
$this->response->body(“You said : ” . $a);
}
Now in your browser go to http://mydemo.com/index.php/welcome/echo/ImGood
This gives o/p:->You said : ImGood
Look at https://github.com/shreyavshetty/BloggingSite