0

I get a php yii error:

trying to get property of non-object.

What is wrong?

Here is my code:

public function actiondnyparentchild()
{
    $parentTitleId = $_GET['contentTitleId'];
    $query = 'SELECT contentTitleId, marathiTitle FROM dnycontenttitle WHERE contentTitleId IN
        (SELECT childTitleId FROM dnycontentcategories WHERE parentTitleId='.$parentTitleId.')';
    $resultschild = Yii::app()->db->createCommand($query)->queryAll();
    $mainchild = array();
    foreach($resultschild as $ressubdata)
    {
        $mainchild[] = array(
            "parentId" => $ressubdata->contentTitleId
        );
    } 
    echo "{'contents':".CJSON::encode($mainchild)."} ";  
}
Wilt
  • 41,477
  • 12
  • 152
  • 203
mahesh
  • 9
  • 2
  • 1
    Which line gives you the error? – Masiorama May 20 '15 at 07:09
  • $mainchild[]=array("parentId" =>$ressubdata->contentTitleId); error show in this line – mahesh May 20 '15 at 09:15
  • Then $ressubdata->contentTitleId can be empty. Just check with property_exists of other php built-in functions – Masiorama May 20 '15 at 09:17
  • Yes. $ressubdata->contentTitleId empty. But var_dump($ressubdata) show data { 'contents': [ { "parentId": { "contentTitleId": "1122", "marathiTitle": "\u092d\u093e\u0930\u0924\u093e\u091a\u093e \u092d\u0942\u0917\u094b\u0932 \u0935\u093f\u092d\u093e\u0917" } }, – mahesh May 20 '15 at 09:47
  • That is a json object, store as string in $ressubdata. Search for how to decode a json string e read it. – Masiorama May 20 '15 at 09:54

0 Answers0