php yii framework issue with objects (2)
<p>This is somewhat the continuation to the question I already posted "<a href="https://stackoverflow.com/questions/35070908/php-yii-framework-issue-with-objects/35072060#35072060">php yii framework issue with objects</a>", but a new problem arised so I am posting a new question for the sake of better code display and explanation of what's wrong. This is the problematic part of the code:</p>

<pre><code>&lt;?php $this-&gt;widget('zii.widgets.grid.CGridView', array(
'id'=&gt;'predmet-grid',
'dataProvider'=&gt;$model-&gt;search(),
'filter'=&gt;$model,
'columns'=&gt;array(
    //array(
    //  'name'=&gt;'naziv',
    //  'value'=&gt;$model-&gt;studijskiProgram-&gt;naziv,
    //),
    'sp_id',
    'naziv',
    'semestar',
    'predavanja',
    'vjezbe',
    //array(
    //  'class'=&gt;'CButtonColumn',
    //),
),
)); ?&gt;
</code></pre>

<p>And this is the code of the model class where relations are located:</p>

<pre><code>&lt;?php

/**
* This is the model class for table "predmet".
*
* The followings are the available columns in table 'predmet':
* @property integer $id
* @property integer $sp_id
* @property string $naziv
* @property integer $semestar
* @property integer $predavanja
* @property integer $vjezbe
*/
   class Predmet extends CActiveRecord
   {
     /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Predmet the static model class
     */

const STATUS_O = "O";
const STATUS_I = "I";
const STATUS_VP = "VP";

public static function model($className=__CLASS__)
{
    return parent::model($className);
}

/**
 * @return string the associated database table name
 */
public function tableName()
{
    return 'predmet';
}

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('sp_id, naziv, semestar, predavanja, vjezbe, status', 'required'),
        array('sp_id, semestar, predavanja, vjezbe', 'numerical', 'integerOnly'=&gt;true),
        array('naziv', 'length', 'max'=&gt;100),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, sp_id, naziv, semestar, predavanja, vjezbe, status', 'safe', 'on'=&gt;'search'),
    );
}

/**
 * @return array relational rules.
 */
public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.

    //POVEZUJEMO PREDMET I STUDIJSKI PROGRAM
    //BELONGS_TO ide za vezu jedan u vise(kad na stranu 1 pisemo kome pripada)
    //HASMANY ili HAS_MANY (?) JE ZA VISE U JEDAN

    /*ovo prvo 'studijskiProgram' je kao pokazivac na studijski program s kojim je povezan
    Neka imamo $predmet. da bi pristupili nazivu studijskog programa kome pripada, koristicemo:
    $predmet-&gt;studijskiProgram-&gt;naziv
    */
    return array(
        'studijskiProgram' =&gt; array(self::BELONGS_TO, 'StudijskiProgram', 'sp_id')
    );
}

/**
 * @return array customized attribute labels (name=&gt;label)
 */
public function attributeLabels()
{
    return array(
        'id' =&gt; 'ID',
        'sp_id' =&gt; 'Studijski program',
        'naziv' =&gt; 'Naziv',
        'semestar' =&gt; 'Semestar',
        'predavanja' =&gt; 'Predavanja',
        'vjezbe' =&gt; 'Vjezbe',
        'status' =&gt; 'Status'
    );
}

/**
 * Retrieves a list of models based on the current search/filter conditions.
 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
 */
public function search()
{
    // Warning: Please modify the following code to remove attributes that
    // should not be searched.

    $criteria=new CDbCriteria;

    $criteria-&gt;compare('id',$this-&gt;id);
    $criteria-&gt;compare('sp_id',$this-&gt;sp_id);
    $criteria-&gt;compare('naziv',$this-&gt;naziv,true);
    $criteria-&gt;compare('semestar',$this-&gt;semestar);
    $criteria-&gt;compare('predavanja',$this-&gt;predavanja);
    $criteria-&gt;compare('vjezbe',$this-&gt;vjezbe);

    return new CActiveDataProvider($this, array(
        'criteria'=&gt;$criteria,
    ));
}


//Funkcija za punjenje Combo box-a (Wombo)
public function uzmiStatusPredmeta()
{
    return array(
            self::STATUS_O =&gt; 'Obavezni',
            self::STATUS_I =&gt; 'Izborni',
            self::STATUS_VP =&gt; 'VP'
    );
}

public function uzmiSpisakStudijskihPrograma()
{
    $query = 'select id, naziv from studijski_program';
    $rezultat = Yii::app()-&gt;db-&gt;createCommand($query)-&gt;queryAll();
    $spisak = CHtml::listData($rezultat,'id','naziv');  //prikazuje naziv, krije ID(valjda radi combo boxa-wombo ?)

    return $spisak;
}
public function vratiProgram()
{
    $query = 'select s.naziv 
    from studijski_program s,predmet p
    where p.sp_id = s.id';
    $rezultat = Yii::app()-&gt;db-&gt;createCommand($query)-&gt;queryScalar();
    //$rezultat1 = implode($rezultat);
    //$rezultat2 = implode($rezultat1);
    return $rezultat;
}
public function vratiProgramId()
{
    $query = 'select s.id 
    from studijski_program s,predmet p
    where p.sp_id = s.id';
    $rezultat = Yii::app()-&gt;db-&gt;createCommand($query)-&gt;queryScalar();
    //$rezultat1 = implode($rezultat);
    //$rezultat2 = implode($rezultat1);
    return $rezultat;
}

}
</code></pre>

<p>As you can see here there exists relation to "studijskiProgram" here using the "sp_id" foreign key in "predmet". However when I am trying to access "naziv" proprety from "studijskiProgram" in the upper part of the code like this:</p>

<pre><code>    array(
        'name'=&gt;'naziv',
        'value'=&gt;$model-&gt;studijskiProgram-&gt;naziv,
    ),
</code></pre>

<p>which was the solution with the previous question where CDeatilView widget is used. For some reason the same thing here doesn't work and reports error of trying to get a proprety of a non object. Any idea what to alter so it would work?</p>