Skip to content

Commit

Permalink
Merge pull request #7 from ufocoder/fix-related-placeholder
Browse files Browse the repository at this point in the history
Fix related placeholder
  • Loading branch information
mohorev committed May 23, 2015
2 parents ff6c219 + 882de74 commit db29d9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class Document extends ActiveRecord
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getCategory()
{
return $this->hasOne(Category::className(), [ 'id' => 'id_category' ]);
}

/**
* @inheritdoc
*/
Expand All @@ -55,8 +63,8 @@ class Document extends ActiveRecord
'class' => UploadBehavior::className(),
'attribute' => 'file',
'scenarios' => ['insert', 'update'],
'path' => '@webroot/upload/docs',
'url' => '@web/upload/docs',
'path' => '@webroot/upload/docs/{category.id}/',
'url' => '@web/upload/docs/{category.id}/',
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected function resolvePath($path)
$model = $this->owner;
return preg_replace_callback('/{([^}]+)}/', function ($matches) use ($model) {
$name = $matches[1];
$attribute = $model->getAttribute($name);
$attribute = ArrayHelper::getValue($model, $name);
if (is_string($attribute) || is_numeric($attribute)) {
return $attribute;
} else {
Expand Down

0 comments on commit db29d9e

Please sign in to comment.