Answer the question
In order to leave comments, you need to log in
How to save to database?
I write a parser that saves data from a third-party site at the entered page address,
I get an array of this kind
array(1){
['category']=>"lorem ipsum"
['description']=>'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.'
['page']=>'За словесными горами ';
['desc_page']=>'Далеко-далеко за словесными горами в стране гласных и согласных живут рыбные тексты. Вдали от всех живут они в буквенных домах на берегу Семантика большого языкового океана.'
};
Answer the question
In order to leave comments, you need to log in
First look for the category on the title. If you did not find such a category, then add it to the database. If found, then use it further in the code.
Something like this:
$category = Category::find()->where(['title' => $title])->one();
if($category === null) {
$category = new Category();
// Заполняем данными
// ...
$category->save();
}
echo $category->title;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question