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
Сомневался в добавлении этого в статью. Добавлю комментом. Обычно делаем через таблицу связей. Типичный пример для блога и постов. | |
Таблица post(модель Post) — храним метаинформацию, которая не имеет отношения к контенту. | |
То есть такие поля: id, owner_id, date_create, date_update. | |
Таблица post_lang(модель PostLang) — связь контента по языкам. Поля: id, post_id, lang_id, name, description. | |
Соответственно поля post_id — это id из таблицы post, lang_id — это id из таблицы lang. name и | |
description — контент на соответствующем языке. | |
В модель Post добавляем отношение: | |
public function getContent($lang_id=null) | |
{ |
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
&НаКлиенте | |
Функция РассчитатьПроцентНаценки(ЦенаЗакупки, ЦенаПродажи) | |
ПроцентНаценки = 0; | |
Если ЦенаЗакупки <> 0 Тогда | |
ПроцентНаценки = (ЦенаПродажи - ЦенаЗакупки) * 100 / ЦенаЗакупки; | |
КонецЕсли; | |
Возврат ПроцентНаценки; | |
КонецФункции |
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
public function behaviors() | |
{ | |
return [ | |
'timestamp' => [ | |
'class' => 'yii\behaviors\TimestampBehavior', | |
'attributes' => [ | |
\yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['date_create', 'date_update'], | |
\yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['date_update'], | |
], | |
], |
NewerOlder