Created
February 10, 2016 05:29
-
-
Save metalagman/c15334c91fb2a0968456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace common\components; | |
/** | |
* Class ActiveRecord | |
* @package common\components | |
*/ | |
class ActiveRecord extends \yii\db\ActiveRecord | |
{ | |
/** | |
* @param $runValidation | |
* @param $attributeNames | |
* @return bool | |
*/ | |
public function trySave($runValidation = true, $attributeNames = null) | |
{ | |
if (false === $this->save($runValidation, $attributeNames)) { | |
throw new \LogicException; | |
} | |
return true; | |
} | |
/** | |
* @param $runValidation | |
* @param $attributeNames | |
* @return bool | |
*/ | |
public function tryUpdate($runValidation = true, $attributeNames = null) | |
{ | |
if (false === $this->update($runValidation, $attributeNames)) { | |
throw new \LogicException; | |
} | |
return true; | |
} | |
/** | |
* @param $runValidation | |
* @param $attributeNames | |
* @return bool | |
*/ | |
public function tryInsert($runValidation = true, $attributeNames = null) | |
{ | |
if (false === $this->insert($runValidation, $attributeNames)) { | |
throw new \LogicException; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment