-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,25 +7,34 @@ | |
/** | ||
* DynamicModel extends from yii\base\Dynamic Model. | ||
* | ||
* Additional Dynamic Model to provide attribute labels. | ||
* Additional Dynamic Model to provide attribute labels and attribute hints. | ||
* | ||
* ```php | ||
* $model = new DynamicModel(['query']); | ||
* $model->attributeLabels = ['query' => 'Search term']; | ||
* $model->attributeHints = ['query' => 'Enter a search term in order to find articles.']; | ||
* $model->addRule(['query'], 'string'); | ||
* $model->addRule(['query'], 'required'); | ||
* ``` | ||
* | ||
* @author Basil Suter <[email protected]> | ||
* @since 1.0.0 | ||
*/ | ||
class DynamicModel extends \yii\base\DynamicModel | ||
{ | ||
/** | ||
* @var array An array with key value pairing where key is the attribute and value the label. | ||
* @since 1.0.15 | ||
*/ | ||
public $attributeHints = []; | ||
|
||
/** | ||
* @var array Assignable attributes by array where key is the label key value the label for the key. | ||
*/ | ||
public $attributeLabels = []; | ||
|
||
/** | ||
* In addition to the attributeLabels() values can also be be passed by propertie and run trough Yii::t process. | ||
* | ||
* @inheritDoc | ||
* | ||
* @see \yii\base\Model::attributeLabels() | ||
* @return array | ||
* {@inheritDoc} | ||
*/ | ||
public function attributeLabels() | ||
{ | ||
|
@@ -36,4 +45,17 @@ public function attributeLabels() | |
|
||
return $labels; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function attributeHints() | ||
{ | ||
$hints = []; | ||
foreach ($this->attributeHints as $key => $value) { | ||
$hints[$key] = Yii::t('app', $value); | ||
} | ||
|
||
return $hints; | ||
} | ||
} |