$source = $this->translations['*']; if ($source instanceof MessageSource) { return $source; } else { return $this->translations[$category] = $this->translations['*'] = Yii::createObject($source); } } } throw new InvalidConfigException("Unable to locate message source for category '$category'."); } }
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message. * @param string $language the language code (e.g. `en-US`, `en`). * @return string the translated and formatted message. */ public function translate($category, $message, $params, $language) { $messageSource = $this->getMessageSource($category); $translation = $messageSource->translate($category, $message, $language); if ($translation === false) { return $this->format($message, $params, $messageSource->sourceLanguage); } else { return $this->format($translation, $params, $language); }
* [[\yii\base\Application::language|application language]] will be used. * @return string the translated message. */ public static function t($category, $message, $params = [], $language = null) { if (static::$app !== null) { return static::$app->getI18n()->translate($category, $message, $params, $language ?: static::$app->language); } else { $p = []; foreach ((array) $params as $name => $value) { $p['{' . $name . '}'] = $value; }
{ return [ 'title' => Yii::t('easyii', 'Title'), 'category_id' => Yii::t('easyii', 'Category'), 'image_file' => Yii::t('easyii', 'Image'), 'description' => Yii::t('easyii', 'Description'), 'available' => Yii::t('easyii/catalogtobacco', 'Available'), 'price' => Yii::t('easyii/catalogtobacco', 'Price'), 'discount' => Yii::t('easyii/catalogtobacco', 'Discount'), 'time' => Yii::t('easyii', 'Date'), 'slug' => Yii::t('easyii', 'Slug'), ]; }
* @return string the attribute label * @see generateAttributeLabel() * @see attributeLabels() */ public function getAttributeLabel($attribute) { $labels = $this->attributeLabels(); if (isset($labels[$attribute])) { return $labels[$attribute]; } elseif (strpos($attribute, '.')) { $attributeParts = explode('.', $attribute); $neededAttribute = array_pop($attributeParts);
$model = new $this->query->modelClass; if (empty($sort->attributes)) { foreach ($model->attributes() as $attribute) { $sort->attributes[$attribute] = [ 'asc' => [$attribute => SORT_ASC], 'desc' => [$attribute => SORT_DESC], 'label' => $model->getAttributeLabel($attribute), ]; } } else { foreach ($sort->attributes as $attribute => $config) { if (!isset($config['label'])) { $sort->attributes[$attribute]['label'] = $model->getAttributeLabel($attribute);
/** * @return Sort|boolean the sorting object. If this is false, it means the sorting is disabled. */ public function getSort() { if ($this->_sort === null) { $this->setSort([]); } return $this->_sort; } /**
} $query = clone $this->query; if (($pagination = $this->getPagination()) !== false) { $pagination->totalCount = $this->getTotalCount(); $query->limit($pagination->getLimit())->offset($pagination->getOffset()); } if (($sort = $this->getSort()) !== false) { $query->addOrderBy($sort->getOrders()); } return $query->all($this->db); }
* * @param boolean $forcePrepare whether to force data preparation even if it has been done before. */ public function prepare($forcePrepare = false) { if ($forcePrepare || $this->_models === null) { $this->_models = $this->prepareModels(); } if ($forcePrepare || $this->_keys === null) { $this->_keys = $this->prepareKeys($this->_models); } }
/** * Returns the data models in the current page. * @return array the list of data models in the current page. */ public function getModels() { $this->prepare(); return $this->_models; } /** * Sets the data models in the current page.
*/ public function __get($name) { $getter = 'get' . $name; if (method_exists($this, $getter)) { // read property, e.g. getName() return $this->$getter(); } else { // behavior property $this->ensureBehaviors(); foreach ($this->_behaviors as $behavior) { if ($behavior->canGetProperty($name)) { return $behavior->$name;
$this->_adp = new ActiveDataProvider([ 'query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : [] ]); foreach($this->_adp->models as $model){ $result[] = new ItemObject($model); } return $result; } public function fieldOptions($name, $firstOption = '')
return $this->render('cat', [ 'cat' => $cat, 'items' => $cat->getItems([ 'pagination' => ['pageSize' => 20], 'filters' => $filters, 'orderBy' => 'title', ]), 'filterForm' => $filterForm ]); } } public function actionCatalogItem($slug = null)
$args = $this->controller->bindActionParams($this, $params); Yii::trace('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); Yii::$app->controller = $oldController; return $result; } else { $id = $this->getUniqueId(); throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
$params = $this->catchAll; unset($params[0]); } try { Yii::trace("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } else { $response = $this->getResponse(); if ($result !== null) { $response->data = $result;
try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/app/config/web.php'); (new yii\web\Application($config))->run();
$_GET = [ 'slug' => 'tabak', ];