no data show in ListView

trying to make a simple application




    public function actionView($id)

    {

        $count = Yii::$app->db->createCommand('SELECT COUNT(*) FROM '. $id)->queryScalar();


        $dataProvider = new SqlDataProvider([

        'sql' => 'SELECT * FROM '. $id,

        'totalCount' => $count,

          'pagination' => [

              'pageSize' => 20,

          ],

      ]);




        return $this->render('view',['dataProvider' => $dataProvider]);

    }



I just want to display data from a table in the ListView::widget




use yii\widgets\ListView;


echo ListView::widget( [

    'dataProvider' => $dataProvider,

    'itemOptions' => ['class' => 'item'],

] );



Example table 8_mart





CREATE TABLE IF NOT EXISTS `8_mart` (

  `id` mediumint(10) NOT NULL AUTO_INCREMENT,

  `sms` text CHARACTER SET cp1251 NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=631 ;


--

-- Дамп данных таблицы `8_mart`

--


INSERT INTO `8_mart` (`id`, `sms`) VALUES

(1, 'Нежный март, счастья трель...<br>К нам стучит чудный день!<br>День улыбок, любви,<br>День Прекрасной Весны,<br>Что согреет теплом,<br>Тайной и волшебством.<br>И подарит свой свет,<br>И весенний букет!\r'),

(2, 'Пусть весь год женский день не кончается, Пусть в честь Вас прожурчат ручейки, Пусть Вам солнце <br> всю жизнь улыбается, А мужчины пycть дарят цветы!<br> \r'),



The result can be seen here smstochka.ru/frontend/web/index.php/sms/8_mart

Please help me to understand

Run gii. It has option to generate ListView, you can only customize it.

such tables from which the sample will need to do quite a lot, that’s why I bring in actionView ($ id)

$ id is the name of the table from where I currently need to get data

You should add itemView property.

Look at example

Thank You

Pasman p

It’s working

smstochka.ru/frontend/web/index.php/sms/8_mart

:slight_smile: