Deploying Кohana3 on the local XAMPP-powered Windows host
Суббота, 19 сентября 2009 г.Рубрика: Web frameworks
Метки: Kohana | обучение
Просмотров: 3062
Подписаться на комментарии по RSS
Это перевод моего русскоязычного тутора Развертывание 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 ![]()
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><img src="http://kupreev.com/uploads/smiles/wink.gif" width="19" height="19" alt="wink" style="border:0;" class="smiley">)')
->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
.
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
Комментариев: 3
Thanks a lot for the translation. Lot of newbies are going to benefit by this.
Я думаю можно уже забрать RC 1. Релиз kohana разворачивается аналогично.
Спасибо, Павел, конечно, все абсолютно аналогично
исправлю