Manufacturer::updateSEOKeyword PHP Méthode

updateSEOKeyword() public méthode

public updateSEOKeyword ( $keyword )
    public function updateSEOKeyword($keyword)
    {
        if (!$this->isNewRecord) {
            $alias = $this->getUrlAlias();
            // if keyword is empty delete url alias
            if (empty($keyword) || is_null($keyword)) {
                if (!is_null($alias)) {
                    return $alias->delete();
                }
                return false;
            } else {
                if (is_null($alias)) {
                    $alias = new UrlAlias();
                    $alias->query = "manufacturer_id={$this->manufacturer_id}";
                }
                $alias->keyword = $keyword;
                return $alias->save();
            }
        } else {
            throw new CException(Yii::t('errors', 'Tried to update SEO Keyword for an object that doesn\'t exists yet.'));
        }
    }

Usage Example

 public function save()
 {
     $manufacturer = Manufacturer::model()->findByPk($this->id);
     if (is_null($manufacturer)) {
         // is insert
         $manufacturer = new Manufacturer();
     }
     $manufacturer->name = $this->name;
     $manufacturer->image = $this->image;
     $manufacturer->sort_order = $this->sortOrder;
     $manufacturer->save();
     // SEO Keyword
     $manufacturer->updateSEOKeyword($this->seoKeyword);
     // Stores
     $manufacturer->clearAllStoresRelations();
     if (isset($this->stores) && count($this->stores)) {
         foreach ($this->stores as $storeId) {
             $manufacturer->addToStore($storeId);
         }
     }
 }