-3

I am new in Yii framework. I have a page frontend/site/home.php, I want to display the number of records from companies table at home.php.(DB name yii2advanced)

Shailesh Yadav
  • 205
  • 3
  • 12
  • You need to post some code where you try to fix your problem. Atleast post your model/controller and view code – Solmyr Dec 08 '17 at 07:57
  • @Solmyr here's my controller code :public function actionHome() { $result = (new \yii\db\Query) ->select('*') ->from('companies') return $this->render('home'); } and home.php code: use yii\helpers\Html; use yii\bootstrap\ActiveForm;

    = "$result"; ?>

    Companies
    – Shailesh Yadav Dec 08 '17 at 08:12
  • 1
    @ShaileshYadav Please post your code in your question instead of as a comment. – Paul Dec 08 '17 at 09:29

1 Answers1

3

Simply use count function to get count of records from a table, like -

$count = YourModel::find()->count();
echo $count;
Rohit Suthar
  • 3,528
  • 1
  • 42
  • 48
Ajil MV
  • 58
  • 1
  • 7