1

When I dump all variables of a model in controller, I can see:

[CActiveRecord:_attributes] => array
    (
        'id' => '524'
        'version' => '0'
        'created' => '2015-06-24 12:37:27'
        'documents_id' => '528'
    )

How can I get for example 'documents_id' element and use it in that controller?

2 Answers 2

1

You can get attribute value of model by model object.

$modelobj = new Modelname();

$modelobj->documents_id;
Sign up to request clarification or add additional context in comments.

Comments

0

You have two ways:

1- Convert the Object to array

function convertObject2Array($object){
    $finalArray = array();
    foreach($object as $propertyName => $propertyValue)
        $finalArray[$propertyName] = $propertyValue;
    return $finalArray;
}

2- Use Yii::app()->db->createCommand instead of $this->loadModel($ID) like the followings:

$SQL_II = "SELECT * FROM users WHERE id = '" . $ID . "'";
$dbCommand = Yii::app()->db->createCommand($SQL_II);
$finalArray = $dbCommand->queryAll();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.