This file contains 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
В fields.yaml отдельно прописать my_field@update - то есть состояние кнопки при update. | |
Пример: | |
my_field: | |
type: text | |
... | |
my_field@update: | |
type: text | |
disabled: true | |
... |
This file contains 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
Если нужна связь типа "Запись имеет комментарий(ии)", то есть без pivot таблицы, | |
а просто таблица комментариев имеет доп. столбец с id записи, то: | |
1. модели Запись прописываем: | |
public $hasMany = [ | |
'comments' => 'author\myplugin\Models\Comment' | |
]; | |
2. Контроллеру Записи прописываем: | |
public $implement = ['Backend\Behaviors\RelationController'] и public $relationConfig = 'config_relation.yaml'; |
This file contains 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
Устанавливаем October (установщиком или через Composer) | |
В папке с October устанавливаем пакет vue-cli (npm i -g vue-cli) и создаём vue приложение (vue init webpack my-app), | |
внутри папки my-app выполняем (npm i) и в итоге npm run dev (консоль и так подскажет) | |
Внутри my-app - npm i --save-dev axios (для запросов get, post к api) | |
Axios — это JavaScript-библиотека для выполнения либо HTTP-запросов в Node.js, либо XMLHttpRequests в браузере. | |
.htaccess (шоб axios мог получать данные): | |
Header add Access-Control-Allow-Origin "*" | |
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" |
This file contains 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
function onSubmit() | |
{ | |
// get all post data | |
$data = post(); | |
$form = YourModel::make($data); | |
// set specific field as we need | |
$form->form_files = Input::file('form_files'); | |
$form->save(); | |
// Note: |
This file contains 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
Модель::all()->last()->vlk_file->getPath(); | |
Другой вариант: | |
// Это в обычной функции | |
$images = array(); | |
// $records равен запросу в бд с выборкой чего-либо | |
foreach($records as $index => $record) | |
$images[$index] = \System\Models\File::where('attachment_id', $record->id)->get(); |
This file contains 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
В любой непонятной ситуации - dd($this). | |
Например, кнопка редактирования на странице preview: | |
<a href="<?= Backend::url('estar/hotel/records/update', $this->params[0]) ?>" class="btn btn-default"> | |
Редактировать | |
</a> |
This file contains 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
https://octobercms.com/docs/database/relations#many-to-many | |
Таблица, которая нужна для связывания записей одной таблицы с записями другой называется сross reference table. | |
Нужно получить значение из другой связанной таблицы? Прописываем для той модели, записи которой выводим: | |
public $belongsToMany = [ | |
'phones' => ['estar\hotel\Models\Phone', 'table' => 'estar_hotel_users_phones'] | |
]; |
This file contains 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
use \October\Rain\Exception\ValidationException; | |
class myModel extends Model | |
{ | |
public function beforeSave() | |
{ | |
// date_in, date_out - поля с датами! | |
$start = $this->date_in; | |
$end = $this->date_out; | |
$check = Db::table('mytable') |
This file contains 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
class MyModel extends Model | |
{ | |
... | |
public function afterCreate() | |
{ | |
// вот значение purged поля _extras | |
// подчкёркивание (_) означает, что это поле (которое в форме) не будет сохраняться в данной модели MyModel. | |
// но я хочу получить его для сохранения в другую модель. | |
$val = $this->getOriginalPurgeValue('_extras'); |
This file contains 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
В билдере этих свойств нет, поэтому лезем в fileds.yaml в папке модели и добавляем (свой текст): | |
on: Да | |
off: Нет |
NewerOlder