Yii Framework Forum: CDetailView Error - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CDetailView Error Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 24 February 2010 - 08:14 PM

hi...

I get problem when using CDetailView

here is my model

Class SuperAdmins extends CActiveRecord {
    ....

    public function findUsername($userId){
        if(!isset(self::$_model)){
            self::loadModel();
        }
        $Criteria = new CDbCriteria();
        $Criteria->condition = "id = '$userId'";
        $result = self::$_model->find($Criteria);
        return $result->username;
    }
}


when I try to display with CDetailView the result is still ID user not username. but when I try to set manually like this:

Class SuperAdmins extends CActiveRecord {
    ....

    public function findUsername($userId){
        if(!isset(self::$_model)){
            self::loadModel();
        }
        $Criteria = new CDbCriteria();
        $Criteria->condition = "id = '1'"; // I sett manuall id = '1' and it works
        $result = self::$_model->find($Criteria);
        return $result->username;
    }
}


here is the view

    $this->widget('zii.widgets.CDetailView', array(
        'data' => $model,
        'attributes'=>array(
                'id',
                'display_name',
                'email',
                'username',
                'created_time:datetime',
                array(
                    'name' => 'created_by',
                    'value' => SuperAdmins::findUsername($data->created_by) //  it doesn't work
                ),
                'edited_time:datetime',
                array(
                    'name' => 'edited_by',
                    'value' => SuperAdmins::findUsername($data->edited_by) //  it doesn't work
                ),
                ....
        ),
    ));


how to resolve this problem..

thanks....
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 24 February 2010 - 08:25 PM

function getUsername() {} ??
0

#3 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 24 February 2010 - 08:30 PM

View Postjerry2801, on 24 February 2010 - 08:25 PM, said:

function getUsername() {} ??


this is function to get username

    public function findUsername($userId){
        if(!isset(self::$_model)){
            self::loadModel();
        }
        $Criteria = new CDbCriteria();
        $Criteria->condition = "id = '$userId'"; 
        $result = self::$_model->find($Criteria);
        return $result->username;
    }


thanks for your respon sir.. I have try to display this function in CDetailView, but appear CDetailView is cannot displaying other function not like CGridView. :unsure:
Thanks and Kind Regards
------
DanDinDun
0

#4 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 24 February 2010 - 08:55 PM

Dan Din Dun, try basic troubleshooting, such as a var_dump($userId); in your method, as well as var_dump($result);

Post back with your results please
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#5 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 25 February 2010 - 03:33 AM

View Postintel352, on 24 February 2010 - 08:55 PM, said:

Dan Din Dun, try basic troubleshooting, such as a var_dump($userId); in your method, as well as var_dump($result);

Post back with your results please


hi sir, I have try to var_dump($result) it is outputing NULL

so I try to var_dump($userId); and still outputting NULL

I guess the problem is in CDetailView is don't store the data in $data variable.

but I try to access $model->id not $data->id (it is works). confused :blink:

so

    $this->widget('zii.widgets.CDetailView', array(
        'data' => $model,
        'attributes'=>array(
                'id',
                'display_name',
                'email',
                'username',
                'created_time:datetime',
                array(
                    'name' => 'created_by',
                    'value' => SuperAdmins::findUsername($data->created_by) //  it doesn't work so I change into $model->created_by and works
                ),
                'edited_time:datetime',
                array(
                    'name' => 'edited_by',
                    'value' => SuperAdmins::findUsername($data->edited_by) //  it doesn't work so I change into $model->edited_by and works
                ),
                ....
        ),
    ));


can you explain about this sir??

thanks
Thanks and Kind Regards
------
DanDinDun
0

#6 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 25 February 2010 - 04:02 AM

public function findUsername($userId) {}

must change to:

public static function findUsername($userId) {}
0

#7 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 25 February 2010 - 04:49 AM

View Postjerry2801, on 25 February 2010 - 04:02 AM, said:

public function findUsername($userId) {}

must change to:

public static function findUsername($userId) {}


ok sir, thanks.. now it works :-) GREAT
Thanks and Kind Regards
------
DanDinDun
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users