Skip to content

Instantly share code, notes, and snippets.

@metalagman
Created February 10, 2016 05:29
Show Gist options
  • Save metalagman/c15334c91fb2a0968456 to your computer and use it in GitHub Desktop.
Save metalagman/c15334c91fb2a0968456 to your computer and use it in GitHub Desktop.
<?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