public function actionAjaxAdd() { if (Yii::app()->request->isAjaxRequest && Yii::app()->user->checkAccess('blockip_admin')) { $postValue = CHtml::encode(strip_tags(Yii::app()->request->getParam('value'))); $pk = CHtml::encode(strip_tags(Yii::app()->request->getParam('pk'))); if ($postValue) { $blockIpModel = BlockIp::model()->find('ip = :ip', array(':ip' => $postValue)); if ($blockIpModel) { # IP уже есть $msg = 'already_exists'; } else { $blockIpModel = new BlockIp(); $blockIpModel->ip = $postValue; $blockIpModel->ip_long = ip2long($postValue); $blockIpModel->date_created = new CDbExpression('NOW()'); if ($blockIpModel->save()) { $msg = 'ok'; } else { $msg = 'save_error'; } } } else { $msg = 'no_value'; } echo CJSON::encode(array('msg' => $msg, 'value' => $postValue, 'pk' => $pk)); Yii::app()->end(); } }
private static function setCache() { $blockIps = BlockIp::model()->cache(param('cachingTime', 1209600), self::getDependency())->findAll(); if ($blockIps) { foreach ($blockIps as $item) { self::$_cache[$item->ip_long] = $item->ip; } } }