Код: Выделить всё
public function beforeSave($insert){
if (parent::beforeSave($insert)) {
if($this->scenario = 'create'){
$this->access_token = sha1(mt_rand(10000, 99999) . time() . mt_rand(10000, 99999));
$this->access_token_exp = new Expression('NOW()+INTERVAL ' . Yii::$app->settings->getValue('interval_access_token_exp '). ' DAY');
$this->renew_token = sha1(mt_rand(10000, 99999) . time() . mt_rand(10000, 99999));
$this->renew_token_exp = new Expression('NOW()+INTERVAL ' . Yii::$app->settings->getValue('interval_renew_token_exp') . ' DAY');
}
return true;
}
return false;
}
....
if(!$token_for_insert->save()){
....
Код: Выделить всё
class SettingsComponent extends Component {
public $_settings;
public $connection;
public function init(){
$this->connection = Yii::$app->db;
parent::init();
}
public function getValue($name){
$row = $this->connection->createCommand('SELECT * FROM '.Settings::tableName())->queryOne();
Yii::warning(serialize($row[$name])); // Condition
if($row[$name]) { // Condition
return $row[$name];
}
else throw new BadRequestHttpException('No this param !');
}
}
Error:
Код: Выделить всё
yii\web\BadRequestHttpException: No this param ! in /var/www/pmn/common/components/SettingsComponent.php:41
Stack trace:
#0 /var/www/pmn/backend/models/Tokens.php(99): common\components\SettingsComponent->getValue('interval_access...')
#1 /var/www/pmn/vendor/yiisoft/yii2/db/ActiveRecord.php(490): backend\models\Tokens->beforeSave(true)
....