Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting unknown property: backend\models\Category::title #9

Open
shahzadthathal opened this issue Nov 26, 2016 · 0 comments
Open

Getting unknown property: backend\models\Category::title #9

shahzadthathal opened this issue Nov 26, 2016 · 0 comments

Comments

@shahzadthathal
Copy link

shahzadthathal commented Nov 26, 2016

Hi,

Can you please help me to solve this issue?
I'm getting this error when I try to access category title like this way: echo $category->title; here is my model code

    public function getTranslations()
    {
        return $this->hasMany(CategoryTranslation::className(), ['category_id' => 'id']);
    } 
   public function getParentCatList(){
      $model = self::find()->with('translations')->all();
        echo count($model); // 3 records
        foreach ($model as $category) {
            echo $category->title;// this gives me error.
        }
        //echo "pre";
        print_r($model);
        exit;
  }

and print_r($model) is displaying this results.

3

Array
(
    [0] => backend\models\Category Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 1
                    [parent_id] => 
                    [status] => 1
                    [sort_order] => 1
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 1
                    [parent_id] => 
                    [status] => 1
                    [sort_order] => 1
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                    [translations] => Array
                        (
                            [0] => backend\models\CategoryTranslation Object
                                (
                                    [_attributes:yii\db\BaseActiveRecord:private] => Array
                                        (
                                            [id] => 1
                                            [category_id] => 1
                                            [language] => en
                                            [slug] => conveyors
                                            [title] => Conveyors
                                        )

                                    [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                                        (
                                            [id] => 1
                                            [category_id] => 1
                                            [language] => en
                                            [slug] => conveyors
                                            [title] => Conveyors
                                        )

                                    [_related:yii\db\BaseActiveRecord:private] => Array
                                        (
                                        )

                                    [_errors:yii\base\Model:private] => 
                                    [_validators:yii\base\Model:private] => 
                                    [_scenario:yii\base\Model:private] => default
                                    [_events:yii\base\Component:private] => Array
                                        (
                                        )

                                    [_behaviors:yii\base\Component:private] => Array
                                        (
                                        )

                                )

                        )

                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )

    [1] => backend\models\Category Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 2
                    [parent_id] => 1
                    [status] => 1
                    [sort_order] => 2
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 2
                    [parent_id] => 1
                    [status] => 1
                    [sort_order] => 2
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                    [translations] => Array
                        (
                            [0] => backend\models\CategoryTranslation Object
                                (
                                    [_attributes:yii\db\BaseActiveRecord:private] => Array
                                        (
                                            [id] => 2
                                            [category_id] => 2
                                            [language] => en
                                            [slug] => chain-conveyors
                                            [title] => Chain conveyors
                                        )

                                    [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                                        (
                                            [id] => 2
                                            [category_id] => 2
                                            [language] => en
                                            [slug] => chain-conveyors
                                            [title] => Chain conveyors
                                        )

                                    [_related:yii\db\BaseActiveRecord:private] => Array
                                        (
                                        )

                                    [_errors:yii\base\Model:private] => 
                                    [_validators:yii\base\Model:private] => 
                                    [_scenario:yii\base\Model:private] => default
                                    [_events:yii\base\Component:private] => Array
                                        (
                                        )

                                    [_behaviors:yii\base\Component:private] => Array
                                        (
                                        )

                                )

                        )

                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )

    [2] => backend\models\Category Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 3
                    [parent_id] => 
                    [status] => 1
                    [sort_order] => 0
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 3
                    [parent_id] => 
                    [status] => 1
                    [sort_order] => 0
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                    [translations] => Array
                        (
                            [0] => backend\models\CategoryTranslation Object
                                (
                                    [_attributes:yii\db\BaseActiveRecord:private] => Array
                                        (
                                            [id] => 3
                                            [category_id] => 3
                                            [language] => en
                                            [slug] => easy2cut-sheet-cutter 
                                            [title] => Easy2Cut - Sheet cutter 
                                        )

                                    [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                                        (
                                            [id] => 3
                                            [category_id] => 3
                                            [language] => en
                                            [slug] => easy2cut-sheet-cutter 
                                            [title] => Easy2Cut - Sheet cutter 
                                        )

                                    [_related:yii\db\BaseActiveRecord:private] => Array
                                        (
                                        )

                                    [_errors:yii\base\Model:private] => 
                                    [_validators:yii\base\Model:private] => 
                                    [_scenario:yii\base\Model:private] => default
                                    [_events:yii\base\Component:private] => Array
                                        (
                                        )

                                    [_behaviors:yii\base\Component:private] => Array
                                        (
                                        )

                                )

                        )

                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )

)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant