I have a line of code like this

    <h1> <?= Html::img('/yii2/basic/uploads/images/'.$model->id.'.'.$model->file_ext) ?></h1>

and it works. However if I upload it to a new server where it is no longer in the ‘yii2’ directory this code is going to break. Is there a better way of doing this? I’ve been reading about path aliases but I don’t really get how to set them up or use them.

Hi, using/defining aliases is pretty simple, but for most thing you have predefined ones:

One of them is @web alias, so you could do something like (in your view):

 <h1><img src="<?= Yii::getAlias('@web') . '/images/' . $model->id . '.' . $model->file_ext ?>" /> </h1>

And you have to put your images under web accessible directory.

Your’s directory - /yii2/basic/uploads/images/ - does not look like the one.