📜 ⬆️ ⬇️

Flea market on Kohanaphp. Part 1

Do the same as here , only using Kohanaphp:

Differences between kohanaphp and codeigniter:

* Uses PHP 5 OOP
* Database abstraction using SQL helpers
* Various session drivers (native, database and cookie)
* Event handler
* Based on CodeIgniter
Get kohana at the kohanaphp website .

')
Actually there should be no problems with the installation, we do everything the same as the author in the original article with LAMP.

Kohanaphp configuration


The kohanaphp configuration is a bit different:
<?php
// , CodeIgniter
//... site_domain base_url
$config['site_domain'] = 'habrastore.ru';
//....
// kohanaphp i18n,
// , internal_cache . FALSE,
// live -- .
$config['internal_cache'] = FALSE;

// kohanaphp , .
// TRUE
$config['enable_hooks'] = array('multilingual');

/**
* Log thresholds:
* 0 - Disable logging
* 1 - Errors and exceptions
* 2 - Warnings
* 3 - Notices
* 4 - Debugging
*/
//
$config['log_threshold'] = 1;

/**
* Message logging directory.
*/
$config['log_directory'] = APPPATH.'logs';

/**
* Additional resource paths, or "modules". Each path can either be absolute
* or relative to the docroot. Modules can include any resource that can exist
* in your application directory, configuration files, controllers, views, etc.
*/
// . FS .
// ,
$config['modules'] = array
(
MODPATH.'auth', // Authentication
MODPATH.'grige', // ( PEAR, =) )
MODPATH.'service',// API - last.fm
MODPATH.'openid',
MODPATH.'payment',
// MODPATH.'kodoc', // Self-generating documentation
// MODPATH.'media', // Media caching and compression
);

I note that there is no autoloud option, so there is no need to look for it in the config.

Further at the expense of support for different languages, as I recall. You can decide in a completely different way. Do the following:
modify /appllication/config/locale.php:
<?php
$config['language'] = array('ru_RU');

/**
* Locale timezone. Defaults to use the server timezone.
* @see php.net/timezones
*/
$config['timezone'] = 'Europe/Brussels';

/**
* All languages this site is available in.
*/
$config['allowed_languages'] = array
(
'ru' => 'ru_RU',
'en' => 'en_US',
);

/**
*
*/
$config['lang'] = 'ru';


Multilingual


And do a little hook (on the right) to support multilingual URLs.
application / hooks / multilingual.php:
<?php

Event::add_after('system.routing', array('Router', 'find_uri'), 'site_lang');

function site_lang()
{

//
$allowed_languages = Kohana::config('locale.allowed_languages');
//
if (preg_match('~^[az]{2}(?=/|$)~i', Router::$current_uri, $matches))
{
$lang = strtolower($matches[0]);

// ?
if ( ! array_key_exists($lang, $allowed_languages)) {
Event::run('system.404');
}

//
Kohana::config_set('locale.lang', $lang);
Kohana::config_set('locale.language', array($allowed_languages[$lang]));

// Kohana::setup()
setlocale(LC_ALL, $allowed_languages[$lang].'.UTF-8');
Router::$current_uri = substr(Router::$current_uri, 3);

if (empty(Router::$current_uri)) {
Router::$current_uri = 'store';
}
}

// =(
else
{
Kohana::config_set('locale.language', array($allowed_languages[Kohana::config('locale.lang')]));
}
}


Ha, now it's left to create a helper that will give us beautiful urls
application / helpers / MY_html.php
<?php

class html extends html_Core {
public static function lanchor($uri, $title = NULL, $attributes = NULL, $protocol = NULL)
{
return self::anchor(Kohana::config('locale.lang').'/'.$uri, $title, $attributes, $protocol);
}
}



Here it seems everything is done in the same way as in the article about CodeIgniter.

Data base


Oh yeah, I forgot about the database. I do not think that it will differ from the base that the author of the original article offers us, I will just mention that I will use my native ORM kohanaphp, therefore I will write right away how I will call the tables and fields:


That's all


Since Kohana fork CodeignIter, the train of thought should be understandable for CI-shnik. Questions and clarifications are welcome. I have chosen this path for not knowingly using a controller for such things, because it seems to me that the controller should deal with other things following the MVC paradigm and should be language-agnostic.

Also at the expense of Russian: I'm sorry, he is not my own, because I think there are mistakes. If you notice - please let me know, I will correct.

Source: https://habr.com/ru/post/41657/


All Articles