O
O
on_click2019-07-31 22:48:15
Yii
on_click, 2019-07-31 22:48:15

What is the correct way to call a widget with the following data in yupe?

Greetings, I am just starting to get acquainted with yii, but I suspect that the question is not very smart, please be understanding)
On the article archive page in a certain category, the widget is called by the following code

$this->widget('application.modules.user.widgets.UsersList', array(
'condition' => $condition, 'type' => $type));

Widget code:
<?php

class UsersList extends yupe\widgets\YWidget
{
    public $view      = 'main';
    public $condition = array();
    public $type      = "professional";

    public function run()
    {

        $id = $this->getId();

        if ($this->type == "professional") {
            $users = User::model()->professionals();
        }
        elseif ($this->type == "company") {
            $users = User::model()->companies();
        }
        elseif ($this->type == "contest") {
            $users = User::model()->contests();
        }
        else {
            $users = User::model()->organizations();
        }

        $models = $users->with('categories', 'tags')->findAll($this->condition);

        $this->render($this->view, array('models' => $models, 'type' => $this->type, 'id' => $id));
    }
}

in $condition I see
Array
(
    [together] => 1
    [condition] => categories.id = :cid
    [params] => Array
        (
            [:cid] => 159
        )

    [group] => t.id
    [limit] => 20
    [order] => t.id DESC
)

on the main page I try to call with the same parameters, but I get an error
The property "UsersList.cid" is not defined (tried various variations, this is one of the tried ones)
$this->widget('application.modules.user.widgets.UsersList', array(
'condition' => array(
  'limit' => 12, 
  'together' => true, 
  'group' => 't.id'
), 
'type' =>'contest',
'cid' => 159
));

please tell me how to call the widget with this condition

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-08-01
@on_click

<?= $this->widget('application.modules.user.widgets.UsersList', array(
    'condition' => array(
        'limit' => 2,
        'together' => true,
        'group' => 't.id',
        'condition' => 'categories.id=":cid"',
        'params' => [':cid' => $cid]
    ),
    'type' =>'contest',
    'view' => 'contest'
)); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question