Answer the question
In order to leave comments, you need to log in
How to call action in YII2?
there is an actionBook that accepts data using POST and writes the base.
In actionTest I need (probably using CurlFactory) to pass an array with any data to this actionBook.
Essentially emulate receiving data from outside. How to do it?
Answer the question
In order to leave comments, you need to log in
Could be something like this
public function actionBook() {
$data = $_POST['Book'];
$result = $this->saveBook($data);
}
public function actionTest() {
$data = [
'title' => 'Test title',
'desctiption' => 'Test description'
];
$result = $this->saveBook($data);
}
protected function saveBook($data) {
$model = new Book();
if ($model->load($data, '') && $model->validate()) {
retrun $model->save();
} else {
return false;
}
}
else if - is unnecessary in principle. One if is enough. The main thing is to clearly understand how to correctly set the condition, by what criterion to determine that the news is also displayed in announcements.
https://wordpress.org/plugins/optimize-images-resizing/ almost every task in WordPress already has a plugin). Haven't tried it myself yet.
We gave the solution to freelance, as it will be implemented, I will write here
$attachments = get_children( array(
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'post_status' => 'publish',
'exclude' => array( get_post_thumbnail_id() )
) );
//Теперь в переменной $attachments хранятся айдишники всех изображений которые прикреплены к посту.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question