Answer the question
In order to leave comments, you need to log in
How to find category id?
I want to write a parser that receives information from the site, it turns out such an array
$array(
[category]=>'Loren 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.'
[name]=>'За словесными горами'
[desc]=>'Далеко-далеко за словесными горами в стране гласных и согласных живут рыбные тексты. Вдали от всех живут они в буквенных домах на берегу Семантика большого языкового океана.'
[cat]=>'Lorem ipsum');
$category= new Category();
$post =new Post();
if ($model->load(Yii::$app->request->post()) ) {
$category->name = $array['category'];
$category->description=$array['description'];
$category->save();
$post->name=$array['name'];
$post->description=$array['desc'];
}
Answer the question
In order to leave comments, you need to log in
I think you can use the relay www.yiiframework.com/doc-2.0/guide-db-active-recor...
1. record id is obtained after ->save(true)
2. if all else fails, then read about before after save() method
$category= new Category();
$post =new Post();
$category->save();
$post->category_id = $category->id;
$post->save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question