本文整理汇总了PHP中BaseModel::beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseModel::beforeSave方法的具体用法?PHP BaseModel::beforeSave怎么用?PHP BaseModel::beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseModel
的用法示例。
在下文中一共展示了BaseModel::beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
public function beforeSave()
{
if ($this->position == '') {
$max = OrderStatus::model()->orderByPositionDesc()->find();
if ($max) {
$this->position = (int) $max->position + 1;
} else {
$this->position = 0;
}
}
return parent::beforeSave();
}
示例2: beforeSave
/**
* @return bool
*/
public function beforeSave()
{
if (empty($this->url)) {
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
$this->url = SlugHelper::run($this->title);
}
// Check if url available
if ($this->isNewRecord) {
$test = Event::model()->withUrl($this->url)->count();
} else {
$test = Event::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id));
}
if ($test > 0) {
$this->url .= '-' . date('YmdHis');
}
return parent::beforeSave();
}
示例3: beforeSave
public function beforeSave()
{
if (parent::beforeSave()) {
$reurl = false;
if ($this->isNewRecord) {
$this->_newRec = true;
$this->author = Yii::app()->user ? Yii::app()->user->id : null;
} else {
$this->_curr = self::findByPk($this->id);
if ($this->_curr) {
if ($this->title != $this->_curr->title) {
$reurl = true;
}
}
}
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
if (!$this->url || $reurl) {
// $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim));
$this->url = SlugHelper::run($this->title, 'yandex');
} else {
$this->url = SlugHelper::run($this->url, 'yandex');
}
$unique = $this->url;
$addsuffix = 0;
while ($this->checkUniqueUrl($unique) > 0) {
$unique = $this->url . $suffix . '-' . $addsuffix;
$addsuffix++;
}
$this->url = $unique;
$this->description = trim(MHelper::String()->purifyFromScript($this->description));
$this->updated_date = date('Y-m-d H:i:s');
return true;
} else {
return false;
}
}
示例4: beforeSave
/**
* @return bool
*/
public function beforeSave()
{
return parent::beforeSave();
}
示例5: beforeSave
public function beforeSave()
{
if (empty($this->url)) {
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
$this->url = SlugHelper::run(preg_replace('/\\s{2,}/', ' ', $this->name));
}
// Check if url available
if ($this->isNewRecord) {
$test = StoreProduct::model()->withUrl($this->url)->count();
$this->created = date('Y-m-d H:i:s');
} else {
$test = StoreProduct::model()->withUrl($this->url)->count('t.id!=:id', array(':id' => $this->id));
}
// Create unique url
if ($test > 0) {
$this->url .= '-' . date('YmdHis');
}
return parent::beforeSave();
}
示例6: beforeSave
/**
* @return bool
*/
public function beforeSave()
{
// Set new password
if ($this->new_password) {
$this->password = User::encodePassword($this->new_password);
}
if ($this->isNewRecord) {
if (!$this->created_at) {
$this->created_at = date('Y-m-d H:i:s');
}
$this->login_ip = Yii::app()->request->userHostAddress;
if (!$this->hasErrors()) {
$this->password = User::encodePassword($this->password);
}
}
return parent::beforeSave();
}
示例7: beforeSave
public function beforeSave()
{
if(parent::beforeSave()) {
$reurl = false;
if($this->isNewRecord) {
$this->_newRec = true;
$this->author = (Yii::app()->user)?Yii::app()->user->id:null;
} else {
$this->_curr = self::findByPk($this->id,array('select'=>'status_org'));
if($this->_curr) {
if($this->title != $this->_curr->title)
$reurl = true;
}
}
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
if(!$this->url || $reurl){
// $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim));
$this->url = SlugHelper::run($this->title, 'yandex');
} else {
$this->url = SlugHelper::run($this->url, 'yandex');
}
$this->description = trim(MHelper::String()->purifyFromScript($this->description));
$this->updated_date = date('Y-m-d H:i:s');
return true;
} else
return false;
}
示例8: beforeSave
/**
* @return bool
*/
public function beforeSave()
{
if (!$this->created && $this->isNewRecord) {
$this->created = date('Y-m-d H:i:s');
}
if (!$this->updated) {
$this->updated = date('Y-m-d H:i:s');
}
if (!Yii::app()->user->isGuest) {
$this->user_id = Yii::app()->user->id;
}
if (empty($this->url)) {
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
$this->url = SlugHelper::run($this->title);
}
// Check if url available
if ($this->isNewRecord) {
$test = Page::model()->withUrl($this->url)->count();
} else {
$test = Page::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id));
}
if ($test > 0) {
$this->url .= '-' . date('YmdHis');
}
return parent::beforeSave();
}
示例9: beforeSave
/**
* Before save.
*/
public function beforeSave()
{
if($this->isNewRecord)
{
$this->ip_address = Yii::app()->request->userHostAddress;
$this->created = date('Y-m-d H:i:s');
if($this->status == self::STATUS_APPROVED){
if($this->rating) {
$this->starRating($this->object_pk, $this->rating);
}
}
} else {
$this->_curr = self::findByPk($this->id);
if($this->status == self::STATUS_APPROVED && $this->_curr->status != self::STATUS_APPROVED){
if($this->rating) {
$this->starRating($this->object_pk, $this->rating);
}
} else if($this->status != self::STATUS_APPROVED && $this->_curr->status == self::STATUS_APPROVED){
if($this->rating) {
if($this->_curr->rating != $this->rating){
$this->starRatingBack($this->object_pk, $this->_curr->rating);
} else {
$this->starRatingBack($this->object_pk, $this->rating);
}
}
} else {
if($this->_curr->rating != $this->rating){
$this->starRatingBack($this->object_pk, $this->_curr->rating);
$this->starRating($this->object_pk, $this->rating);
} else { // do nothing with rating
}
}
}
$this->updated = date('Y-m-d H:i:s');
return parent::beforeSave();
}
示例10: beforeSave
/**
* Before save.
*/
public function beforeSave()
{
if ($this->isNewRecord) {
$this->status = $this->defaultStatus;
$this->ip_address = Yii::app()->request->userHostAddress;
$this->created = date('Y-m-d H:i:s');
}
$this->updated = date('Y-m-d H:i:s');
return parent::beforeSave();
}
示例11: beforeSave
public function beforeSave()
{
if (empty($this->url)) {
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
$this->url = SlugHelper::run($this->name);
}
// Check if url available
if ($this->isNewRecord) {
$test = StoreCategory::model()->withUrl($this->url)->count();
} else {
$test = StoreCategory::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id));
}
// Create unique url
if ($test > 0) {
$this->url .= '-' . date('YmdHis');
}
$this->rebuildFullPath();
return parent::beforeSave();
}
示例12: beforeSave
/**
* @return bool
*/
public function beforeSave()
{
if ($this->isNewRecord) {
$this->secret_key = $this->createSecretKey();
$this->ip_address = Yii::app()->request->userHostAddress;
$this->created = date('Y-m-d H:i:s');
if (!Yii::app()->user->isGuest) {
$this->user_id = Yii::app()->user->id;
}
}
$this->updated = date('Y-m-d H:i:s');
// Set `New` status
if (!$this->status_id) {
$this->status_id = 1;
}
return parent::beforeSave();
}
示例13: beforeSave
public function beforeSave()
{
if (!$this->created && $this->isNewRecord) {
$this->created = date('Y-m-d H:i:s');
}
if (!$this->updated) {
$this->updated = date('Y-m-d H:i:s');
}
if (empty($this->url)) {
Yii::import('ext.SlugHelper.SlugHelper');
$this->url = SlugHelper::run($this->name);
}
// Check if url available
if ($this->isNewRecord) {
$test = PageCategory::model()->withUrl($this->url)->count('parent_id=:parent_id', array(':parent_id' => $this->parent_id));
} else {
$test = PageCategory::model()->withUrl($this->url)->count('id!=:id AND parent_id=:parent_id', array(':id' => $this->id, ':parent_id' => $this->parent_id));
}
if ($test > 0) {
$this->url .= '-' . date('YmdHis');
}
return parent::beforeSave();
}
示例14: beforeSave
public function beforeSave()
{
if(parent::beforeSave()) {
$ydata = false;
$reurl = false;
if($this->isNewRecord) {
$this->ip_address = Yii::app()->request->userHostAddress;
$ydata = true;
$this->_newRec = true;
$this->author = (!Yii::app()->user->isGuest)?Yii::app()->user->id:null;
} else {
$this->_curr = self::findByPk($this->id,array('select'=>'city_id,status,address,lat,lng'));
if($this->_curr) {
if($this->title != $this->_curr->title)
$reurl = true;
}
if($this->city_id != $this->_curr->city_id || $this->address != $this->_curr->address || !$this->lat || !$this->lng){
$ydata = true;
}
}
if($ydata == true){
if(!empty($this->address)){
$address = $this->address;
$params = array(
'geocode' => $address, // адрес
'format' => 'json', // формат ответа
'results' => 1, // количество выводимых результатов
// 'key' => '...', // ваш api key
);
$response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&')));
$result = '';
if ($response && isset($response->response) && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0)
{
$result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos;
if($result){
$exp_str1 = explode(" ", $result);
$this->lat = $exp_str1[1];
$this->lng = $exp_str1[0];
// $this->yanData();
}
}
}
}
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
if(!$this->url || $reurl){
$this->url = SlugHelper::run($this->title, 'yandex');
} else {
$this->url = SlugHelper::run($this->url, 'yandex');
}
$this->updated_date = date('Y-m-d H:i:s');
return true;
} else
return false;
}
示例15: beforeSave
public function beforeSave()
{
if(parent::beforeSave()) {
// Create slug
Yii::import('ext.SlugHelper.SlugHelper');
if(!$this->name){
$this->name = SlugHelper::run($this->title, 'yandex');
} else {
$this->name = SlugHelper::run($this->name, 'yandex');
}
$unique = $this->name;
$suffix = 1;
while ($this->checkUniqueUrl($unique) > 0){
$unique = $this->name.$suffix;
$suffix++;
}
$this->name = $unique;
return true;
} else
return false;
}