diff --git a/Module.php b/Module.php index dbd5de3..d483328 100755 --- a/Module.php +++ b/Module.php @@ -3,6 +3,7 @@ namespace rico\yii2images; +use rico\yii2images\models\PlaceHolder; use yii; use rico\yii2images\models\Image; @@ -16,6 +17,8 @@ class Module extends \yii\base\Module public $controllerNamespace = 'rico\yii2images\controllers'; + public $placeHolderPath; + @@ -45,6 +48,10 @@ public function getImage($item, $dirtyAlias) ':alias' => $alias ])*/ ->one(); + if(!$image){ + $image = new PlaceHolder(); + } + return $image; } diff --git a/behaviors/ImageBehave.php b/behaviors/ImageBehave.php index 3e5d42e..c353ee8 100755 --- a/behaviors/ImageBehave.php +++ b/behaviors/ImageBehave.php @@ -172,7 +172,7 @@ public function getImages() $imageRecords = $imageQuery->all(); if(!$imageRecords){ - return []; + return [new models\PlaceHolder()]; } return $imageRecords; } @@ -191,7 +191,7 @@ public function getImage() $img = $imageQuery->one(); if(!$img){ - return null; + return new models\PlaceHolder(); } return $img; diff --git a/models/PlaceHolder.php b/models/PlaceHolder.php index dd8a4ad..60cacb7 100644 --- a/models/PlaceHolder.php +++ b/models/PlaceHolder.php @@ -11,22 +11,39 @@ namespace rico\yii2images\models; +/** + * TODO: check path to save and all image method for placeholder + */ -class PlaceHolder extends Image { - public function getUrl($size = false){ - $url = $this->getModule()->placeHolderUrl; - if(!$url){ - throw new \Exception('PlaceHolder image must have url setting!!!'); - } - return $url; - } +use yii; + +class PlaceHolder extends Image +{ - public function getPathToOrigin(){ + private $modelName = ''; + private $itemId = ''; + public $filePath = 'placeHolder.png'; + public $urlAlias = 'placeHolder'; - $url = $this->getModule()->placeHolderPath; - if(!$url){ + + /* public function getUrl($size = false){ + $url = $this->getModule()->placeHolderUrl; + if(!$url){ + throw new \Exception('PlaceHolder image must have url setting!!!'); + } + return $url; + }*/ + + public function getPathToOrigin() + { + + $url = Yii::getAlias($this->getModule()->placeHolderPath); + if (!$url) { throw new \Exception('PlaceHolder image must have path setting!!!'); } return $url; } -} \ No newline at end of file + + +} +