Deploying Кohana3 on the local XAMPP-powered Windows host

Views: 5987Comments: 3
Web frameworks

Это перевод моего русскоязычного тутора Развертывание Kohana3 на XAMPP под Windows

This is the translation of my Kohana deployment tutorial in Russian

1. Routine procedure with XAMPP — create folder in htdocs/ (and subfolder for document root): for me it was ko3.loc/ and ko3.loc/www/, then add in apache/conf/extra/httpd-vhosts something like that (replace D:\xampp\ by your XAMPP location)

<VirtualHost *:80> 
    ServerAdmin admin@ko3.loc 
    DocumentRoot D:\xampp\htdocs\ko3.loc\www\
    ServerName ko3.loc
    ServerAlias www.ko3.loc
</VirtualHost>

If you want .htaccess to work, simply ensure that in D:\xampp\apache\conf\httpd.conf  AllowOverride directives are set to All and allowing access from all. Alternatively you can override your default AllowOverride None in actual VirtualHost entry by means of putting there

<Directory "D:\xampp\htdocs\ko3.loc\www ">
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Then add to %Windows%\System32\drivers\etc\hosts something like

127.0.0.1       ko3.loc

2. Copy distributive in www/, start Apache and using preferred browser go to http://ko3.loc.

3. After successful pass of system requirements test rename or delete install.php.

4. Refresh http://ko3.loc in the browser — see “hello, world!”. Seems that all works. But let’s add a little bit more functionality. For example, add two other web-pages.

5. Due to Ivan Brotkin’s introduction we can now that a page can be added by implementation in controller one more method named like “action_...”, where in place of dots a page slug should be written. I’ve named additional pages “page1” and “page2”. So our example Controller_Welcome will be like 

class Controller_Welcome extends Controller {
    public function action_index()
    {
        $this->request->response = 'hello, world!';
    }
       
    public function action_page1()
    {
         $this->request->response = 'hello, world<br />page 1!';
    }
       
    public function action_page2()
    {
        $this->request->response = 'hello, world<br />page 2!';
    }
}

6. Do not forget to change .htaccess like

# Installation directory
RewriteBase /

Refresh the “page1” or “page2” in the browser and see new cool debug-panel with an error message smile

7. To fix that fault modify in application/bootstrap.php system initialization settings:

Kohana::init(array('base_url' => '/', 'index_file' => ''));

Go to the  http://ko3.loc/welcome/page1 or http://ko3.loc/welcome/page2.  Enjoy during 20-30 sec!

8. But what to do with our long URL? Present “site” is too simple thus bulky URL is redundant. No problem: replace default route in application/bootstrap.php by

Route::set('default', '(<action>(/<id>))')
    ->defaults(array(
        'controller' => 'welcome',
        'action'     => 'index',
    ));

It means that Controller_Welcome will always be our default controller, and we’ll have only controller method and its parameter in the URL.

Go to the http://ko3.loc/page1 and enjoy smile.

9. Want something more complicated? Maybe dream about a little navigation? It’s reasonable. Let's make some automatic navigation.

First create a new controller method to build a simple navigation panel.

protected function _simple_nav()
{
}

Then use the class reflection to get controller methods

$class = new ReflectionClass('Controller_Welcome');
       
$methods = $class->getMethods();

Next make a loop to go over each method checking whether it renders a page and public

$slugs = '';
       
foreach ($methods as $method_object)
{
    $pos = strpos($method_object->name, 'action_');
           
           
    if ($pos !== 0)
    {
               
        continue;
    }
           
    $slug = substr_replace($method_object->name, '', 0, 7);
               
    if ($slug === '')
    {
        continue;
    }
               
    $m = new ReflectionMethod('Controller_Welcome',$method_object->name);
              
    if ($m->isPublic())
    {
        $slugs .= HTML::anchor($slug, url::title($slug)).'<br />';
    }
           
                       
}

Finally call our nav method where we need it (of course, you can do that in __construct() or before() but this time I prefer to call it manually)

$this->request->response = $this->_simple_nav().'<p>hello, world!!</p>';

That’s all!

PS Controller_Welcome can be downloaded from here.

Also published in English Kohana3 stuff

Views in Kohana3

Simple HMVC-widget in Kohana3

Comments: 3 RSS

1 NetChaos 20-09-2009 00:34

Thanks a lot for the translation. Lot of newbies are going to benefit by this.

2 Павел 22-09-2009 02:20

Я думаю можно уже забрать RC 1. Релиз kohana разворачивается аналогично.

3 Александр Купреев 22-09-2009 11:51

Спасибо, Павел, конечно, все абсолютно аналогично

исправлю

Оставьте комментарий!


Используйте нормальные имена.

     

  

Если вы уже зарегистрированы как комментатор или хотите зарегистрироваться, укажите пароль и свой действующий email. При регистрации на указанный адрес придет письмо с кодом активации и ссылкой на ваш персональный аккаунт, где вы сможете изменить свои данные, включая адрес сайта, ник, описание, контакты и т.д., а также подписку на новые комментарии.

MaxSiteAuth. Войти через loginza

(обязательно)