Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

[Решено] Правильные окончания (helper)


Recommended Posts

Захотел окончания правильные сделать, вылазиет 1 раз ошибка и после рефреша исчезает, т.е. на новых куках ошибки... как исправить? 
 

Notice: Undefined index: language in category.php 
Undefined variable: endingArray in helper/ending.php on line 17
Undefined variable: endingArray in helper/ending.php on line 25

В контролере categoty.php
 

$this->load->helper('ending');
$data['products'][] = array(
...
'reviews'      => reviewEnding((int)$result['reviews'], $this->request->cookie['language']),
);

В ending.php 
 

function reviewEnding($number, $language) {
	$number = $number % 100;
	if ($language == 'ru-ru') {
		$endingArray = array("отзыв", "отзыва", "отзывов");
	} elseif ($language == 'ua') {
		$endingArray = array( "відгук", "відгуки", "відгуків" );
	} elseif ($language == 'en') {
		$endingArray = array( "review", "reviews", "reviews" );
	}
	if ($number >= 11 && $number <= 19) {
		$ending = $endingArray[2];
	} else {
		$i = $number % 10;
		switch ($i) {
			case (1):
17.				$ending = $endingArray[0];
				break;
			case (2):
			case (3):
			case (4):
			$ending = $endingArray[1];
			break;
			default:
25.				$ending = $endingArray[2];
		}
	}
	return $number . ' ' . $ending;
}

 

Edited by zik920
Link to post
Share on other sites

1. Языковая Кука не пришла
2. массив нужно определить до проверки кодов языков

Link to post
Share on other sites

Так а зачем куки если есть:

$this->config->get('config_language')

Я себе так делал и все работает.

Link to post
Share on other sites

да тут проблема-то вот в чем, ладно с кукой

 

function reviewEnding($number, $language) {
    $number = $number % 100;
    if ($language == 'ru-ru') {
        $endingArray = array("отзыв", "отзыва", "отзывов");
    } elseif ($language == 'ua') {
        $endingArray = array( "відгук", "відгуки", "відгуків" );
    } else {
        $endingArray = array( "review", "reviews", "reviews" );
    }

вот и все решение

Link to post
Share on other sites
7 часов назад, zik920 сказал:

$this->request->cookie['language'])

заменить на как сказал @vtkach

на

$this->config->get('config_language')

Link to post
Share on other sites
55 минут назад, chukcha сказал:

заменить на как сказал @vtkach

на

$this->config->get('config_language')

HTTP ERROR 500
При всех манипуляциях...

Link to post
Share on other sites

Попробовал с нуля внимательно, все получилось. Всем спасибо!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.