Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:35:56+00:00 2026-05-31T14:35:56+00:00

I have a simple post AR class/table. Its based on the blog tutorial so

  • 0

I have a simple “post” AR class/table. Its based on the “blog tutorial” so it serves the same purpose.
I want to be able to embed images into posts. My design was as follows and I wasn’t entirely happy with it so I’ll be happy for your feedback:

Design suggestion: Directory protected/data/posts_files/{post_id} would be the repository of posts “resources” (images in our case, but can be anything). Post authors need to put the used images/files in the right location (after the post is created since its id is needed). My needs are really humble so from convenience point of view this is ok. When a post that include such images is requested, CAssetManager will be called to the rescue, to “publish()” the directory of that post (e.g. protected/data/posts_files/17).
In the posts themselves (in their “content” or “body” – which ever term you prefer), images will be embedded with img tags that the src attribute pointing to the published directory for this post_id in the assets folder (for example, after publishing a specific post, WEBROOT/assets/d379e294/some_image.gif).

Problem is that when the post is created/edited, I do not know what path the CAssetManager will create and return – that seemingly random text string (d379e294 in the example above). So, I need on runtime, when loading the ‘post’, to update its content live, after publishing has been made, with the correct url/paths in the ‘src’ attribute of the img tags (or for every other kind of resource linked in that ‘post’).

This was a little challenging: Initially I went with a PHP variable in the ‘post’ content/body and tried to somehow interpolate it when loading or just before rendering the post. I wasn’t successful. I used PHP’s eval(), which is very bad practice and dangerous by itself, and it kept crashing complaining on the other content within the ‘post’ body.
I resorted to have some simple place holder string in the body of the posts – “ASSETS_URL” and str_replace() it when loading the post with the published assets path that I “now” have at hand (at runtime).

I’m not sure this is the best approach. this place holder string could be needed in some post and besides, that seems like a basic templating engine start and my intuition tells me I’m missing something if I do a simple templating engine inside a framework. I just can pin point on the ‘right’ alternative, the best practice alternative, to do it in Yii.
I wanted to ask for your opinion on this – both on the design of the solution from the higher level and on the design of the implementation itself. Would you change things and make them different?

(I didn’t want to dive into KcFinder so intentionally left it out).

Thanks,
Boaz.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:35:58+00:00Added an answer on May 31, 2026 at 2:35 pm

    Imho, it seems your entire problem arises because you are using CAssetManager. What advantage does it actually give you?

    I would suggest making a directory under your application’s root, say : root/post_files/{post_id}/ and storing the post related files there. You can store paths for related post files in the db, and retrieve the file, when needed, using that stored path.

    I’m no expert, just my suggestion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a blog on something.wordpress.com , I simply want one post to ALWAYS
I have a simple page with a table and i want it to be
I have a simple form as <form method=post action=target.php> <input class=button type=submit value=Submit />
I have a simple form that looks like so <% remote_form_for post, :url =>
I have simple regex \.*\ for me its says select everything between and ,
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a simple Book Author relationship class Author(models.Model): first_name = models.CharField(max_length=125) last_name =
I have simple form: <form action=add.php method=post > <input name=name maxlength=30/><br/> <textarea cols=80 name=description
I have a simple form. Its got one field and a submit button. I
So I have a table with multiple publish and unpublish buttons. Simple buttons: <button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.