Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
systems:yii2:file_upload [2018/02/28 16:34] smayr [Controller] |
systems:yii2:file_upload [2018/03/01 16:22] (current) smayr [View] |
||
---|---|---|---|
Line 468: | Line 468: | ||
== Example Image Upload and Save Filename in DB == | == Example Image Upload and Save Filename in DB == | ||
+ | |||
+ | === Model === | ||
+ | In the model, override '' | ||
+ | <code php> | ||
+ | public function afterSave($insert, | ||
+ | { | ||
+ | if(isset($this-> | ||
+ | $this-> | ||
+ | if(is_object($this-> | ||
+ | $path = Yii:: | ||
+ | $this-> | ||
+ | $this-> | ||
+ | \Yii:: | ||
+ | -> | ||
+ | -> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
=== Controller === | === Controller === | ||
- | Add action '' | + | Add action '' |
<code php> | <code php> | ||
public function actionCreate() | public function actionCreate() | ||
Line 485: | Line 504: | ||
} | } | ||
} | } | ||
+ | </ | ||
- | public function afterSave($insert, | + | === View === |
- | { | + | <code php> |
- | if(isset($this->logo)) { | + | <? |
- | $this->logo = UploadedFile:: | + | |
- | if(is_object($this->logo)) { | + | |
- | $path = Yii:: | + | |
- | $this-> | + | |
- | $this-> | + | |
- | \Yii:: | + | |
- | -> | + | |
- | ->execute(); | + | |
- | } | + | |
- | } | + | |
- | } | + | |
</ | </ | ||
Line 733: | Line 742: | ||
=== View === | === View === | ||
- | File '' | + | File '' |
<code php> | <code php> | ||
<?php | <?php | ||
Line 772: | Line 781: | ||
</ | </ | ||
- | File '' | + | File '' |
<code php> | <code php> | ||
<?php | <?php | ||
Line 819: | Line 828: | ||
</ | </ | ||
</ | </ | ||
+ | </ | ||
+ | |||
+ | Or simply use the Yii modal helper: | ||
+ | <code php> | ||
+ | <?php | ||
+ | $itemImage = (!empty($model-> | ||
+ | Yii:: | ||
+ | '' | ||
+ | ); | ||
+ | |||
+ | // Image Thumbnail | ||
+ | if(!empty($itemImage)) { | ||
+ | echo "< | ||
+ | } else { | ||
+ | echo "< | ||
+ | } | ||
+ | | ||
+ | echo Html:: | ||
+ | [' | ||
+ | [' | ||
+ | ); | ||
+ | |||
+ | // Modal Window | ||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ], | ||
+ | ]); | ||
+ | |||
+ | if(!empty($itemImage)) { | ||
+ | echo "< | ||
+ | } else { | ||
+ | echo "< | ||
+ | } | ||
+ | echo '< | ||
+ | echo ' | ||
+ | echo '</ | ||
+ | |||
+ | yii\bootstrap\Modal:: | ||
+ | ?> | ||
</ | </ |