TopicImages.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\models;
  3. use app\models\base\NewsTopic;
  4. use Yii;
  5. /**
  6. * This is the model class for table "topic_images".
  7. *
  8. * @property int $id
  9. * @property int|null $topic_id
  10. * @property string|null $uploaded_at
  11. * @property string|null $alt
  12. * @property string|null $ext
  13. * @property NewsTopic $topic
  14. */
  15. class TopicImages extends \yii\db\ActiveRecord
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public static function tableName()
  21. {
  22. return 'topic_images';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [['topic_id'], 'integer'],
  31. [['uploaded_at'], 'safe'],
  32. [['alt','ext'], 'string'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'topic_id' => 'Topic ID',
  43. 'uploaded_at' => 'Uploaded At',
  44. 'alt' => 'Alt',
  45. ];
  46. }
  47. public function getTopic(){
  48. return $this->hasOne(NewsTopic::class,["id"=>"topic_id"]);
  49. }
  50. public function getUrl(){
  51. return "/topic-images/{$this->topic_id}/{$this->id}.{$this->ext}";
  52. }
  53. }