Best Practice For Html Code Stored In Database Table

My application displays articles from content that is stored in a database table.

The article in turn is entered by the admin user using a WYSIWYG widget. When editing the article, an image can be inserted inti the wysiwyg field by entering a URL.

This works fine, but is not a flexible option :-

  • The url changes from dev to staging to production servers

  • The url changes for different themes

I suppose the best option might be to use something like

<img src="<?php echo Yii::app()->theme->baseUrl; ?>/images/myimage.png">

but this will involve either changing the WYSIWYG code, or parsing the stored html code, both of whicj I am trying to avoid.

what is the best option to handle this?

Having the same problem. did u find the solution?

Probably I would use a place holder in the stored HTML.

<img src="%%BASE_URL%%/images/myimage.png">

// before saving

$html = str_replace(Yii::app()->theme->baseUrl, '%%BASE_URL%%', $html);

// after loading

$html = str_replace('%%BASE_URL%%', Yii::app()->theme->baseUrl, $html);