Get Data from Models

Hi,

I have a model named customerCredits.php

i have created a function to calculate the sum of credit the customer have




    public function getCustomerCredits()

    {        

        $criteria = new CDbCriteria();

        $criteria->select = 'sum(credits) AS credits';

        $criteria->compare('customer_id', (int)$this->customer_id);

      

        return($this->findAll($criteria));

    }



How can i receive the result in my controller to check if the customer have credits?




$d = CustomerCredits::model()->getCustomerCredits();

            if ($d[0]->credits >= $maxCampaigns) {

                $notify->addWarning(Yii::t('lists', 'You have reached the maximum number of allowed  credits.'));

                $this->redirect(array('campaigns/index'));

            }



But always $d[0]->credits is empty

Hello Jull,

You need to instance the model customercredits




$model= new customercredits;



and you use it in the controller so:





$d = $model->getCustomercredits();



you can check with a var_dump($d).

good luck!

Thanks estebanhere30. It works