I
I
Igor Vasiliev2016-07-20 13:10:51
MySQL
Igor Vasiliev, 2016-07-20 13:10:51

How to shorten file link in DB for Yii2?

I think most web programmers have faced this situation .
Imagine a situation that you have locally made a site , the main content of which is illustrations (pictures), and the path to them is stored in the database .
A vivid example is a site on wordpress , you transfer it from a local server to the Internet and BOOM! All picture content flew! Until you fix all the paths (directories), it can take a lot of time. Of course, I taught myself to remove the domain name before the slash, so that the directory would be saved when changing the domain, but this can not be controlled everywhere, plus in some situations there are problems with incomplete directories, this can be solved by php
<?php $_SERVER['HTTP_HOST'];?>
and changing the domain will not even affect the correct display of letters and links in it. Most CMS write the full path to the file in the database, which causes quite a few problems. If you are transferring a site from one domain to another, and you have up to 100,000 directories leading to the old domain, you can damn everything in the world, since deleting the domain name before the slash, or changing it to a new one manually, is the height of idiocy! Why then programs and computers, if everything has to be done by hand?

It's better to spend time once and do everything right at once than not have time to fix it later.

Мне искренне интересно, есть ли в Yii2 такое решение, сохраняющее директорию без доменного имени?
Пример:
1) http://site.local/folder/folder2/.../file.apx
и
2) /folder/folder2/.../file.apx
--------------------------------------------------------------------------------------
Вопрос: Как сохранять ссылки как в примере (2) ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Никита, 2016-07-20
@Isolution666

Url::to
Yii::getAlias
​​Or urlManager directly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question