Yii Framework Forum: Best Practice For Html Code Stored In Database Table - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Best Practice For Html Code Stored In Database Table Rate Topic: -----

#1 User is offline   Crafter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 10-October 12

Posted 28 September 2013 - 05:30 AM

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?
0

#2 User is offline   gsatya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 25-September 13

Posted 28 September 2013 - 06:59 AM

Having the same problem. did u find the solution?
0

#3 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 28 September 2013 - 08:52 AM

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);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users