Make default attribute for Model in October CMS
Ad
I'm making a backend Ajax form action in Controller.
$this->asExtension('FormController')->create_onSave();
In the field.yaml file there are 4 fields, and all their values go perfectly, validation works.
In the database I need to pass a fifth value: theme, that is just the current active theme, so I don't want to show it on the page.
The problem starts when I'm trying to add it in Model with:
public function beforeSave()
{
$this->attributes['theme'] = Theme::getActiveThemeCode();
}
After adding this method in Model, all 5 values go to the database, but they skip validation, so in the database I can add empty values. What is causing this to go wrong?
Ad
Answer
Ad
I think that you have to assign the value to the property in the current instance instead of try to overwrite the raw values.
public function beforeSave()
{
$this->theme = Theme::getActiveThemeCode();
}
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad