T
T
tigra2016-06-02 10:20:36
Yii
tigra, 2016-06-02 10:20:36

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

5 answer(s)
M
Max, 2016-06-02
@matios

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;
    }
}

G
Gregory, 2015-09-15
@grigruss

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.

M
Mr Crabbz, 2015-09-15
@Punkie

https://wordpress.org/plugins/optimize-images-resizing/ almost every task in WordPress already has a plugin). Haven't tried it myself yet.

S
Soho, 2015-09-15
@focuspro

We gave the solution to freelance, as it will be implemented, I will write here

M
Maxim Martirosov, 2015-10-06
@kalbac

$attachments = get_children( array(
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'post_status' => 'publish',
'exclude' => array( get_post_thumbnail_id() )
) );

//Теперь в переменной $attachments хранятся айдишники всех изображений которые прикреплены к посту.

Paste this code in a loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question