the model [code] the controller [code] the form view code [code] The issue is when…
- User
the model
class Content extends ActiveRecord { use BitmaskTrait; /** * Type * @see app\models\ContentCategory.php * Note: Types are handled via ContentCategory and automatically handled * const TYPE_POST = 'post'; const TYPE_PRODUCT = 'product'; //public const TYPE_CATALOG = 'catalog';//*/ // Status const STATUS_DRAFT = 0; const STATUS_PUBLISH = 1; const STATUS_SOLDOUT = 3; // Purchase options public const PURCHASE_OPTIONS_CART = 1;// 2^0 public const PURCHASE_OPTIONS_INQUIRE = 2;// 2^1 public const PURCHASE_OPTIONS_BUYNOW = 4;// 2^2 public static $templates = ['item', 'artwork', 'article', 'exhibition', 'artist', 'catalog']; protected static array $allowedTemplatesByType = [ ContentCategory::TYPE_POST => ['article', 'exhibition', 'artist', 'catalog'], ContentCategory::TYPE_PRODUCT => ['artwork', 'exhibition', 'item', 'catalog'], //ContentCategory::TYPE_CATALOG => [],// no templates or as needed ]; protected static array $typeMap = [ 'post' => ContentCategory::TYPE_POST, 'product' => ContentCategory::TYPE_PRODUCT, // 'catalog' => ContentCategory::TYPE_CATALOG, ]; public function scenarios(): array { $baseAttributes = [ 'type', 'template', 'category_id', 'category_title', 'status', 'title', 'slug', 'body', 'image_header', 'meta_description', 'meta_keywords', /** * Handled by TimestampBehavior 'created_at', 'updated_at',//*/ /** * Handled by BlameableBehavior 'created_by', 'updated_by',//*/ ]; // Add purchaseOptionsArray here because it's used virtually $baseAttributes[] = 'purchaseOptionsArray'; return [ /** * Base type-only fallback scenarios for safety * * Note: array_merge function will append the scenario rules to the base rules, but * it doesn't handle potential conflicts or overwriting of rules. */ ContentCategory::TYPE_POST => $baseAttributes, ContentCategory::TYPE_PRODUCT => array_merge($baseAttributes, [ 'artist', 'dimensions', 'medium', 'year', 'price', 'purchase_options', 'hide_price', 'quantity', 'product_image_one', 'product_image_two', 'product_image_three', ]), //ContentCategory::TYPE_CATALOG => $baseAttributes, /** * Post type + template scenarios for specific validation */ 'post_article' => $baseAttributes, 'post_exhibition' => array_merge($baseAttributes, [ 'start_date', 'end_date', ]), 'post_catalog' => $baseAttributes, /** * Product type + template scenario */ 'product_artwork' => array_merge($baseAttributes, [ 'artist', 'dimensions', 'medium', 'year', 'price', 'purchase_options', 'hide_price', 'quantity', 'product_image_one', 'product_image_two', 'product_image_three', ]), 'product_item' => array_merge($baseAttributes, [ 'artist', 'price', 'purchase_options', 'quantity', 'product_image_one', 'product_image_two', 'product_image_three', ]), 'product_catalog' => $baseAttributes, /** * Default */ 'default' => $baseAttributes, ]; } public function rules(): array { /** * Rules * Rules are handled by either app\models\forms\** for user access validation, or * handled directly within the model and than view file skipping form model validation * for administration only. */ $rules = [ /** * Required */ [['type', 'template', 'category_id', 'status', 'title', 'body', 'meta_description' /* 'created_by', 'created_at' - handled by BlameableBehavior */], 'required'], /** * Integers * Note: Price is handled as a float/string until custom validation. See below. */ [['category_id', 'status', 'year', 'quantity', /*'price'*, 'purchase_options', Note: Empty int until declared via purchaseOptionsArray */ 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'], /** * Strings */ [['body', 'template', 'meta_description', 'meta_keywords', 'category_title'], 'string'], [['title', 'artist', 'dimensions', 'medium', 'category_title', 'meta_keywords', 'slug'], 'string', 'max' => 255], [['image_header','product_image_one', 'product_image_two', 'product_image_three'], 'string', 'max' => 2000], ['meta_description', 'string', 'max' => $this->_contentSummaryLength], ['template', 'string', 'max' => 50], /** * Boolean */ ['hide_price', 'boolean'], ['hide_price', 'default', 'value' => false], /** * Safe */ ['purchaseOptionsArray', 'safe'],// Allow purchaseOptionsArray for form binding as safe /** * Defaults */ ['status', 'default', 'value' => self::STATUS_DRAFT], ['status', 'in', 'range' => [self::STATUS_DRAFT, self::STATUS_PUBLISH], 'when' => fn($model) => $model->type === ContentCategory::TYPE_POST], ['status', 'in', 'range' => [self::STATUS_DRAFT, self::STATUS_PUBLISH, self:: STATUS_SOLDOUT], 'when' => fn($model) => $model->type === ContentCategory::TYPE_PRODUCT], ['type', 'default', 'value' => ContentCategory::TYPE_POST], ['template', 'default', 'value' => 'article', 'when' => fn($model) => $model->type === ContentCategory::TYPE_POST], ['template', 'default', 'value' => 'item', 'when' => fn($model) => $model->type === ContentCategory::TYPE_PRODUCT], ['purchase_options', 'default', 'value' => self::PURCHASE_OPTIONS_CART | self::PURCHASE_OPTIONS_INQUIRE], /** * Custom validations * A rule must specify both attribute names and validator type */ [['template'], 'validateTemplateByType'], [['meta_description'], 'summaryLength'], //[['price'], 'validateMoney', 'skipOnError' => true],// TODO [['purchaseOptionsArray'], 'validatePurchaseOptions'],// Handled by getter and setter /** * Validation messages within form */ [['price'], 'match', 'pattern' => '/^\d+(\.\d{1,2})?$/', 'message' => \Yii::t('app', 'The price must be a valid decimal number with up to two decimal places.') ], [['price'], 'number', 'min' => 2.00, 'max' => 5000000.00, 'message' => \Yii::t('app', 'The price must be a valid number between $2.00 and $5,000,000.00.') ], [['product_image_one', 'product_image_two', 'product_image_three'], 'url', 'skipOnEmpty' => true, 'message' => \Yii::t('app', 'Product Image URL is not valid.')], /** * Relationships */ ['category_id', 'exist', 'skipOnEmpty' => false, 'skipOnError' => true, 'targetClass' => ContentCategory::class, 'targetAttribute' => ['category_id' => 'id'], 'message' => \Yii::t('app', 'Please select a valid category.')], ['created_by', 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['created_by' => 'id']], ['updated_by', 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['updated_by' => 'id']], ]; $rulesByScenario = [ /** * Post + exhibition requires start and end date maybe (example) */ 'post_exhibition' => [ [['start_date', 'end_date'], 'required'], ], /** * Product specific validations */ 'product_artwork' => [ [['artist', 'price', 'purchase_options', 'quantity', 'product_image_one'], 'required'], ], 'product_item' => [ [['price', 'quantity', 'purchase_options', 'product_image_one'], 'required'], ], ]; /** * Merge rules: rules + scenario rules if any * * Note: array_merge function will append the scenario rules to the base rules, but it * doesn't handle potential conflicts or overwriting of rules. */ $mergedRules = array_merge($rules, $rulesByScenario[$this->scenario] ?? []); //\yii\helpers\VarDumper::dump($mergedRules, 10, true);// TODO Debug scenarios tool return $mergedRules; } public function validateTemplateByType($attribute, $params = []): void { // Can't validate without type set if (!$this->type) { return; } // @see below for getAllowedTemplates(); $allowedTemplates = $this->getAllowedTemplates(); if ($this->$attribute !== null && !in_array($this->$attribute, $allowedTemplates, true)) { $this->addError( $attribute, \Yii::t('app', 'The selected template "{template}" is not allowed for this category.', [ 'template' => $this->$attribute ]) ); return; } } public function beforeValidate(): bool { if (!parent::beforeValidate()) { return false; } // ...custom code here... /** * Set scenario automatically based on `type` and `template` to ensure validation * rules apply correctly. */ if ($this->type && $this->template) { // Construct the combined scenario name by concatenating type and template with an underscore // For example: 'product_artwork', 'post_exhibition' $combinedScenario = $this->type . '_' . $this->template; // Check if scenario exists: use combined, else fallback to type or 'default' if (isset($this->scenarios()[$combinedScenario])) { // If the combined scenario exists, set it as the current scenario $this->setScenario($combinedScenario); } // If combined scenario does not exist, check if a scenario matching just the type exists elseif (isset($this->scenarios()[$this->type])) { // Set the scenario to the type-only scenario (e.g., 'product' or 'post') $this->setScenario($this->type); } // If neither combined nor type-only scenario exists, else { // Fallback to a default scenario to prevent validation errors $this->setScenario('default'); } } // If only 'type' is set (no template) elseif ($this->type) { // Set the scenario to the type scenario $this->setScenario($this->type); } // If neither 'type' nor 'template' is set, else { // Set a generic default scenario so validation can still proceed without errors $this->setScenario('default'); } return true; } public function getAllowedTemplates(): array { // Check if the category relation is loaded and has allowed templates if ($this->category && $this->category->getAllowedTemplates()) { return $this->category->getAllowedTemplates(); } // fallback to global allowed templates by 'type' return self::$allowedTemplatesByType[$this->type] ?? []; } /** * Returns the allowed templates for a given content type statically. * @param int|string $type * @return array * * Use this method when you want the list of allowed templates for a specific * content type without needing an instance of Content. * Example usage: * * print_r(Content::getAllowedTemplatesByType(ContentCategory::TYPE_POST)); * // Output: ['article', 'exhibition', 'artist', 'catalog'] * * print_r(Content::getAllowedTemplatesByType('post')); * // Output: ['article', 'exhibition', 'artist', 'catalog'] * * print_r(Content::getAllowedTemplatesByType('PRODUCT')); * // Output: ['item', 'artwork', 'exhibition', 'catalog'] */ public static function getAllowedTemplatesByType(int|string $type): array { if (is_string($type)) { $type = strtolower($type);// normalize if (isset(self::$typeMap[$type])) { $type = self::$typeMap[$type]; } else { // Unknown string type, return empty or error as you prefer return []; } } return self::$allowedTemplatesByType[$type] ?? []; } /** * Returns the entire mapping of content types to their allowed templates. * @return array * * Use when you want all allowed templates grouped by type. * Example usage: * * $allTemplates = Content::getAllAllowedTemplates(); * * Result: * [ * 'post' => ['article', 'exhibition', 'artist', 'catalog'], * 'product' => ['item', 'artwork', 'exhibition', 'catalog'], * ] */ public static function getAllAllowedTemplates(): array { return self::$allowedTemplatesByType; } /** * Returns a key-value list mapping template keys to their human-friendly labels. * @return array Associative array of template keys and their labels. * * This is useful for generating dropdown lists, checkbox lists, or for displaying * template labels in views. * * Example usage: * * $templateOptions = Content::getTemplateList(); * * Result: * [ * 'item' => 'Item', * 'artwork' => 'Artwork', * 'article' => 'Article', * ... * ] */ public static function getTemplateList(): array { $templates = self::$templates; // Use keys and values the same or map them to friendly labels $labels = [ 'item' => \Yii::t('app', 'Item'), 'artwork' => \Yii::t('app', 'Artwork'), 'article' => \Yii::t('app', 'Article'), 'exhibition' => \Yii::t('app', 'Exhibition'), 'artist' => \Yii::t('app', 'Artist'), 'catalog' => \Yii::t('app', 'Catalog'), ]; $list = []; foreach ($templates as $template) { $list[$template] = $labels[$template] ?? ucfirst($template); } return $list; } - Assistant
- User
since you keep bringing this up
There might be validation errors due to the 'match' or 'number' validation rules on price. Make sure that: price submitted is a well-formed decimal number like 1234.56 It is within the allowed range (min 2.00, max 5000000) Note also your match rule requires: '/^\d+(\.\d{1,2})?$/' Make sure the price string matches this, e.g., 123.45, not 123. or 123,45.and simliar
Check that in your "product_artwork" scenario, price is present in the returned array — which you confirm it is. Then check your rules() method. Yii marks attributes as safe implicitly if they have validation rules defined on them except if you define rules with 'safe' validator or 'unsafe'. I see you have: [['price'], 'match', ...] [['price'], 'number', ...] These implicitly mark price as safe.How would you restructure price in the rules?
- Assistant
- User
is what i have in my _form
<div class="col-md-9"> <?= $form->field($model, 'price')->textInput([ 'class' => 'form-control square', 'maxlength' => true, 'type' => 'number', 'min' => '2.00', 'step' => '0.01', 'aria-label' => \Yii::t('app', 'Amount in dollars (2.00)'), ]); ?> </div> - Assistant
Your current form input configuration:
<?= $form->field($model, 'price')->textInput([ 'class' => 'form-control square', 'maxlength' => true, 'type' => 'number', 'min' => '2.00', 'step' => '0.01', 'aria-label' => \Yii::t('app', 'Amount in dollars (2.00)'), ]); ?> - User
what does skipOnEmpty mean
- Assistant
skipOnEmptyis a common option in Yii2 validation rules that controls whether the validator should skip validation when the attribute value is empty. - User
- Assistant
- User
wait so 'maxlength' => true is for bool only? so checkboxes and such/
- Assistant
- User
whats the default for skipOnEmpty?
- Assistant
The default value for
skipOnEmptyin Yii2 validators istruefor most built-in validators.
What this means in practice:
- By default, if the attribute's value is empty (
null, empty string, empty array, etc.), the validator will not run. - This allows optional attributes to be empty without triggering validation errors unless another rule (like
'required') forces the presence of a value.
Exceptions:
- Some validators (like
RequiredValidator) do not useskipOnEmptybecause their job is to ensure the attribute is not empty. - Custom validators may behave differently if you specify it.
Summary:
Validator - By default, if the attribute's value is empty (
- User
refactor my entire rules to be easier to understand, leave nothing out, full code
- Assistant
- User
What does 'maxlength' => true mean in Yii2 form inputs? The 'maxlength' HTML attribute expects an integer value, specifying the maximum number of characters allowed in an input field. For text inputs, Yii2’s ActiveForm / Html helpers accept 'maxlength' => true as a convenience shortcut that triggers Yii to automatically determine the max length from the model’s validation rules for that attribute (usually string with max => 255 or similar). So: 'maxlength' => true → auto-detect max length from model rules and render the HTML maxlength="N" attribute automatically. 'maxlength' => 10 → explicitly sets max length to 10.write a comment for code regarding this
- Assistant
Certainly! Here's a clear, concise comment you can add above or beside your form input code to explain the
'maxlength' => truebehavior in Yii2:/* * The 'maxlength' => true option in Yii2 ActiveForm inputs is a shortcut that * tells Yii to automatically determine the maximum length for this input field * based on the model's validation rules (typically a 'string' rule with 'max' => N). * This will add the HTML attribute maxlength="N" to the input, helping browsers * enforce the maximum allowed characters at the client side. * * Alternatively, you can set 'maxlength' => 10 to explicitly set maxlength to 10 characters. * * Note: 'maxlength' only applies to text-based inputs (e.g., textInput, textarea). * It is ignored on numeric, checkbox, or select inputs. */ - User
2025-07-09 17:06:12 [::1][1][-][trace][application] Price attribute after load: NULL controllers/ContentController.php:316 2025-07-09 17:06:12 [::1][1][-][trace][application] Save result without validation: true /controllers/ContentController.php:347
2025-07-09 17:06:12 [::1][1][-][error][debug.mode] [debug mode] Content Update Scenario: default; Context: { "combinedScenario": "post_artwork", "currentScenario": "default", "allScenarios": [ 1, 2, "post_article", "post_exhibition", "post_catalog", "product_artwork", "product_item", "product_catalog", "default" ], "category": "debug.mode",
so price is not loading
- Assistant
- User
- Assistant
- User
public function scenarios(): array { $baseAttributes = [ 'type', 'template', 'category_id', 'category_title', 'status', 'title', 'slug', 'body', 'image_header', 'meta_description', 'meta_keywords', /** * Handled by TimestampBehavior 'created_at', 'updated_at',//*/ /** * Handled by BlameableBehavior 'created_by', 'updated_by',//*/ ]; // Add purchaseOptionsArray here because it's used virtually $baseAttributes[] = 'purchaseOptionsArray'; return [ /** * Base type-only fallback scenarios for safety * * Note: array_merge function will append the scenario rules to the base rules, but * it doesn't handle potential conflicts or overwriting of rules. */ ContentCategory::TYPE_POST => $baseAttributes, ContentCategory::TYPE_PRODUCT => array_merge($baseAttributes, [ 'artist', 'dimensions', 'medium', 'year', 'price', 'purchase_options', 'hide_price', 'quantity', 'product_image_one', 'product_image_two', 'product_image_three', ]), //ContentCategory::TYPE_CATALOG => $baseAttributes, /** * Post type + template scenarios for specific validation */ 'post_article' => $baseAttributes, 'post_exhibition' => array_merge($baseAttributes, [ 'start_date', 'end_date', ]), 'post_catalog' => $baseAttributes, /** * Product type + template scenario */ 'product_artwork' => array_merge($baseAttributes, [ 'artist', 'dimensions', 'medium', 'year', 'price', 'purchase_options', 'hide_price', 'quantity', 'product_image_one', 'product_image_two', 'product_image_three', ]), 'product_item' => array_merge($baseAttributes, [ 'artist', 'price', 'purchase_options', 'quantity', 'product_image_one', 'product_image_two', 'product_image_three', ]), 'product_catalog' => $baseAttributes, /** * Default */ 'default' => $baseAttributes, ]; } - Assistant
- User
artwork should work for both post and product
- Assistant
- User
- Assistant
Your latest logs look very good and show that:
- POST data properly submitted.
- User
- Assistant
- User
send the new and complete jquery code that handles all the different type/template
- Assistant
- User
- Assistant
- User
that be great
- Assistant
- User
update this:
/* * JavaScript * CSS Classes to control field visibility: * - Apply the class
.field-postto all form fields that should be shown for content type "post". * - Apply the class.field-productto all form fields that should be shown for content type "product". * - Apply the class.field-exhibitionto fields shown only when the template is "exhibition" (usually for post type). * * Examples: * Shows 'start_date' field only if content type is 'post' and template is 'exhibition'" * * * * Shows 'artist' field only if content type is 'product': * * * * This approach allows fine-grained control of form field visibility without relying on grouping * fields inside containers, enabling more flexible layouts. */with new examples how the jquery works
- Assistant
Certainly! Here's the updated comment block reflecting the new, more flexible CSS class conventions and how the improved jQuery toggles field visibility:
/* * JavaScript * CSS Classes to control field visibility: * - Apply the class `.field-type-{type}` to all form fields shown for a specific content type, * for example `.field-type-post` or `.field-type-product`. * - Apply the class `.field-template-{template}` to all form fields shown for a specific template, * for example `.field-template-artwork` or `.field-template-exhibition`. * - Apply the class `.field-type-template-{type}-{template}` to form fields that should only be * visible for the combined content type and template, for example `.field-type-template-product-artwork`. * * Examples: * Shows 'start_date' field only if content type is 'post': * * <?= $form->field($model, 'start_date', ['options' => ['class' => 'field-type-post']]) ?> * * Shows 'end_date' field only if template is 'exhibition' (regardless of type): * * <?= $form->field($model, 'end_date', ['options' => ['class' => 'field-template-exhibition']]) ?> * * Shows 'artist' field only if content type is 'product' and template is 'artwork': * * <?= $form->field($model, 'artist', ['options' => ['class' => 'field-type-product field-template-artwork field-type-template-product-artwork']]) ?> * * This approach allows fine-grained control of form field visibility based on any combination of content type and template, * without wrapping fields in containers or updating JavaScript for each new type/template. * The JavaScript toggles visibility by these classes, dynamically adapting to available types and templates. */ - User
- Assistant
- User
which out of the three options do you think is best?
- Assistant
Great question! Choosing the best option depends on your UX goals and app logic, but here’s a breakdown:
Option A: Set default category on create in PHP
Pros:
- User
I want the best option, so you said a + b correct?
- Assistant
Yes, exactly! Combining Option A + Option B provides the best user experience and robustness:
-
Option A: Preselect a sensible default category in your controller so new content loads with a valid category selected — users immediately see relevant templates and fields without extra clicks.
-
Option B: Enhance your JavaScript to gracefully handle the case where no category is selected (e.g., if the user manually changes category to blank or your default-setting logic doesn’t apply) by disabling the template dropdown and hiding dependent fields until a category is chosen.
This combination ensures:
- New content creation is as smooth and helpful as possible.
- The interface remains clear and prevents invalid input.
- You cover all edge cases and avoid confusing UX.
Next steps if you want help
- I can help you write the PHP code in your
actionCreateto pick a default category ID intelligently. - Also provide the JS snippet adjustment to detect empty category and disable template dropdown accordingly.
-
- User
so lets do that
- Assistant
- User
this is what I have:
/* Initialization on page load: */ var initialCategoryId = \$category.val(); var initialType = getTypeForCategory(initialCategoryId) || currentType; if (!categoryTemplatesMap || Object.keys(categoryTemplatesMap).length === 0) { /* No categories/templates data available: disable template dropdown & hide fields */ \$template.empty() .append(\$('<option>').val('').text('Select a category first')) .prop('disabled', true); toggleFields(null, null); }not
var initialCategoryId = $('#content-category').val(); if (!categoryTemplatesMap || Object.keys(categoryTemplatesMap).length === 0) { // existing code to disable ... } else { updateTemplateOptions(initialCategoryId); var initialTemplate = $('#content-template').val(); toggleFields(initialType, initialTemplate); } - Assistant
Thanks for clarifying! To incorporate the check for empty or undefined
initialCategoryId(which resolved the problem), and keep inline with what you currently have in your heredoc JS snippet format (with escaped$signs), you want to update your existing snippet like this:/* Initialization on page load: */ var initialCategoryId = \$category.val(); var initialType = getTypeForCategory(initialCategoryId) || currentType; if (!categoryTemplatesMap || Object.keys(categoryTemplatesMap).length === 0 || !initialCategoryId) { /* No categories/templates data available OR no category selected: disable template dropdown & hide fields */ \$template.empty() .append(\$('<option>').val('').text('Select a category first')) .prop('disabled', true); toggleFields(null, null); } else { updateTemplateOptions(initialCategoryId); var initialTemplate = \$template.val(); toggleFields(initialType, initialTemplate); } - User
can you refactor actionUpdate while we are at this
- Assistant
- User
LogHelper::debug('Model after load: ' . json_encode(model->attributes), 'method' => ]); LogHelper::debug('POST data: ' . print_r(model->getAttributes(), true), [ 'method' => ]);
- Assistant
Certainly! Here's a combined and cleaned-up single log statement which consolidates the information from all three logs for better clarity and to avoid redundancy:
LogHelper::debug( "Model and request data at load time:\n" . "Model attributes (json): " . json_encode($model->attributes) . "\n" . "Model attributes (print_r): " . print_r($model->getAttributes(), true) . "\n" . "POST data: " . print_r($request->post(), true), [ 'method' => __METHOD__ ] );Explanation:
- Combines the JSON encoded model attributes and the more verbose
print_rfor model attributes to cover both cases. - Includes the full POST data dump.
- Adds one consolidated debug entry with method context.
- This helps you debug both what the model holds and what was posted in one go but keeps logs cleaner and easier to track.
If you prefer, can also split JSON and print_r into separate lines or simplify depending on your log consumption!
- Combines the JSON encoded model attributes and the more verbose
- User
LogHelper allows array at the end of a message so LogHelper::('message', []);
- Assistant
Got it! Since your
LogHelper::debug()accepts a message string plus a context array, you can put the detailed info into the context array, and keep a clear message.Here’s a clean combined call:
LogHelper::debug('Model and POST data after loading:', [ 'model_attributes_json' => json_encode($model->attributes), 'model_attributes_array' => $model->getAttributes(), 'post_data' => $request->post(), 'method' => __METHOD__, ]);Explanation:
- The first parameter is a concise message.
- The second parameter is a structured array with your data:
- JSON encoded attributes for compactness/log parsers.
- Full attributes array for readability.
- Raw POST data.
- This keeps logs organized and easy to filter or search.
Let me know if you want it smartly formatted or filtered!
- User
LogHelper::debug("Content Update Scenario: " . combinedScenario, 'currentScenario' => scenarios)), 'method' => , ]);
- Assistant
Certainly! Here's a combined version of those two
LogHelper::debugcalls that keeps the information organized and structured, using a single message and context array:LogHelper::debug("Content update scenario and key attributes after scenario set", [ 'combinedScenario' => $combinedScenario, 'currentScenario' => $model->getScenario(), 'allScenarios' => implode(', ', array_keys($scenarios)), 'keyAttributes' => [ 'type' => $model->type, 'template' => $model->template, 'category_id' => $model->category_id, 'price' => $model->price, 'purchase_options' => $model->purchase_options, 'quantity' => $model->quantity, ], 'method' => __METHOD__, ]);Explanation:
- One log entry with descriptive message.
- Scenario info and key attribute values included in the context array.
keyAttributesgrouped for clarity.- Maintains the
methodkey for context.
This approach reduces log clutter and keeps related info together, still easy to filter and analyze.
Let me know if you'd like it formatted differently!