foreach ($filter_temp_arr as $param_str) { $param_arr = explode('-', $param_str); //param_name = $param_arr[0] //param_val = $param_arr[1] if(!array_key_exists($param_arr[0], self::$filter)) { $new_arr_param = [ $param_arr[0] => [$param_arr[1]] ]; self::$filter = array_merge(self::$filter, $new_arr_param); } else{ array_push(self::$filter[$param_arr[0]], $param_arr[1]); //Нужны только уникальные значения массива self::$filter[$param_arr[0]] = array_unique(self::$filter[$param_arr[0]]); } // print_r($param_arr);
//param_name = $param_arr[0] //param_val = $param_arr[1] if(!array_key_exists($param_arr[0], self::$filter)) { $new_arr_param = [ $param_arr[0] => [$param_arr[1]] ]; self::$filter = array_merge(self::$filter, $new_arr_param); } else{ array_push(self::$filter[$param_arr[0]], $param_arr[1]); //Нужны только уникальные значения массива
], false]) ; if(!empty(Yii::$app->request->get('filter_sale'))){ $products->andWhere(['>','products_price_sale', 0]); } Yii::$app->session->set('products_ar_start', $products); MyFilter::my_init(); // var_dump(MyFilter::$filter); //Добавляем параметры фильтра к стартовому подготовленному запросу if(!empty(MyFilter::$filter_str) && !empty(MyFilter::$filter)) {
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
* @param array $config name-value pairs that will be used to initialize the object properties. */ public function __construct($id, $module, $config = []) { $this->id = $id; $this->module = $module; parent::__construct($config); } /** * Declares external actions for the controller. * This method is meant to be overwritten to declare external actions for the controller. * It should return an array, with array keys being action IDs, and array values the corresponding
$dependencies = $this->resolveDependencies($dependencies, $reflection); if (!$reflection->isInstantiable()) { throw new NotInstantiableException($reflection->name); } if (empty($config)) { return $reflection->newInstanceArgs($dependencies); } if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies);
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
* @throws InvalidConfigException if the configuration is invalid. * @see \yii\di\Container */ public static function createObject($type, array $params = []) { if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return static::$container->invoke($type, $params);
$className = ltrim($this->controllerNamespace . '\\' . str_replace('/', '\\', $prefix) . $className, '\\'); if (strpos($className, '-') !== false || !class_exists($className)) { return null; } if (is_subclass_of($className, 'yii\base\Controller')) { $controller = Yii::createObject($className, [$id, $this]); return get_class($controller) === $className ? $controller : null; } elseif (YII_DEBUG) { throw new InvalidConfigException("Controller class must extend from \\yii\\base\\Controller."); } else { return null; }
if (($pos = strrpos($route, '/')) !== false) { $id .= '/' . substr($route, 0, $pos); $route = substr($route, $pos + 1); } $controller = $this->createControllerByID($id); if ($controller === null && $route !== '') { $controller = $this->createControllerByID($id . '/' . $route); $route = ''; } return $controller === null ? false : [$controller, $route];
* @param array $params the parameters to be passed to the action * @return mixed the result of the action. * @throws InvalidRouteException if the requested route cannot be resolved into an action successfully */ public function runAction($route, $params = []) { $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);
$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();
} break; } } $application->run();
$_GET = [ 'filter' => 'custom-collection/12-107/category.html', ]; $_SESSION = [ '__flash' => [], 'user_view_pages' => [ '/catalog/custom-collection/12-107/category.html', ], 'user_session_start_time' => 1711715658, 'path' => '/catalog/custom-collection/12-107/category.html', 'products_ar_start' => unserialize('O:28:"backend\\models\\ProductsQuery":27:{s:3:"sql";N;s:2:"on";N;s:8:"joinWith";N;s:6:"select";N;s:12:"selectOption";N;s:8:"distinct";N;s:4:"from";N;s:7:"groupBy";N;s:4:"join";N;s:6:"having";N;s:5:"union";N;s:6:"params";a:0:{}s:27:"' . "\0" . 'yii\\base\\Component' . "\0" . '_events";a:0:{}s:30:"' . "\0" . 'yii\\base\\Component' . "\0" . '_behaviors";a:0:{}s:5:"where";a:3:{i:0;s:3:"and";i:1;a:3:{i:0;s:3:"and";i:1;a:3:{i:0;s:3:"and";i:1;a:3:{i:0;s:3:"and";i:1;a:1:{s:16:"products_publish";i:1;}i:2;a:3:{i:0;s:1:">";i:1;s:14:"products_price";i:2;i:0;}}i:2;a:3:{i:0;s:2:"!=";i:1;s:19:"products_main_photo";i:2;s:0:"";}}i:2;a:3:{i:0;s:1:">";i:1;s:17:"products_quantity";i:2;i:0;}}i:2;a:4:{i:0;s:8:"not like";i:1;s:12:"products_sku";i:2;a:1:{i:0;s:4:"146%";}i:3;b:0;}}s:5:"limit";N;s:6:"offset";N;s:7:"orderBy";N;s:7:"indexBy";N;s:10:"modelClass";s:24:"frontend\\models\\Products";s:4:"with";N;s:7:"asArray";N;s:8:"multiple";N;s:12:"primaryModel";N;s:4:"link";N;s:3:"via";N;s:9:"inverseOf";N;}'), ];