Answer the question
In order to leave comments, you need to log in
What is the best solution for converting words to html code?
Hello.
--
There are records in the database, such as: 1.jpg|s-500.jpg
and: 6000-z|1000|2000
----
there are a lot of records, so you can REDO them for a whole month, so as not to engage in nonsense, I thought, it would be better to just wrap "images" and "values" in html code.
The first thing I decided was to remove the separating stick, and replace it with a comma, and then wrap it in double quotes to make an array out of this, however, in order to convert, for example, to json, these numbers or words need to be added some value to get :
Then you can easily store at least 50 images in one cell of the table, in the form:
Then it remains to load and update in the action in the form of a json string, how to get data from json - I know.$list = array(1=>"1.jpg", 2=>"s-500.jpg");
{"1":"1.jpg","2":"s-500.jpg"}
But how to convert:
1.jpg|s-500.jpg
to
Without crutches, I can’t imagine, the same somehow needs to be done with the values, you can then use the tag method to write and overwrite data like: 1.jpg|s -500.jpg
The latter will be links. The dilemma is how best to work with such data, because now they are stored in this form, and are separated only by a stick, without spaces.
For a very long time, in pure php, I output such data from a text document, they were just stored in the form:
It was enough to wrap the name in an html tag, and remove the sticks to display a record, in my case, each individual word, by some miracle should end up in:
and in:{"1":"1.jpg","2":"s-500.jpg"}
Имя|Сообщение|Дата
'слово из БД', ['alt' => 'image'])
=Html::img(
<?=Html::a('слово из БД', '/ssilka/'.слово из БД, ['class' => 'myclass']);?>
Answer the question
In order to leave comments, you need to log in
In $data type string from loop
$data = explode("|", $data);
$data = json_encode($data);
You can redo them for a whole month
public function actionPerehrehyzchit(){
$old = OldModel::find()->all();
$errors = [];
foreach($old as $one){
$data = explode("|", $one->someAttr);
foreach($data as $one_data){
$new_model = new NewModel();
$new_model->someId = $one->id;
$new_model->imageName = $one_data;
if(!$new_model->save()){
$errors[$one->id][] = $new_model->errors;
}
}
}
echo '<pre>';
print_r($errors);
echo '<pre>';
return 'я фсё, удали экшен';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question