C
C
ColdSpirit2015-08-18 17:50:12
Yii
ColdSpirit, 2015-08-18 17:50:12

How to correctly pass data from action to actionAjax (not) through a form?

Hello. I'm trying to implement image loading for a news page.
How I did the loading logic:

  1. The user requests an edit page.
  2. The actionEdit is launched - the post id is taken from the GET parameter and the images in the "/images/{post id}" folder are searched
  3. All found images are displayed through the view, which accepts some settings, like the size of the element containing the image.
  4. The user sends a new image to the site via ajax. ActionAjaxFileUpload should get the image, validate it and save it to the same folder ("/images/{post id}") with a new name.
  5. After that, render-view is launched, which requires the same parameters (exactly those that were in point 2).

Problem such:
In point 4 on ajax I cannot receive post id in any way. Since this is an ajax request, the id cannot be obtained via GET. For POST - writing id somewhere in a form or in an ajax script seems bad to me, because the user can change them.
With point 5 the same problem, only with parameters-options.
To get around the problem, I think to use tokens:
  1. When passing the page to the user, generate a token, save the options in the database as {key: token, value: options}.
  2. Save this token to a form or script.
  3. When receiving an image and a token, the site accesses the database, retrieves the entry, if it exists, and uses it.

But for some reason I don't like the option with tokens.
Are there any normal ways to pass data so that the user can neither see nor change it?
#Supplementary question:
To load an image, I use the Item model, which should not be used anywhere else. To search and process uploaded images, I use the image manager class (launched in the controller).
It turns out that the Item model that interacts with the form must also pass data to and from the form that is not directly related to loading images (such as a token, for example).
I don't think it should be like this, but I couldn't think of anything better. What can you advise on this matter?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question