jionelmessi
جمعه 10 بهمن 1393, 21:22 عصر
با سلام
من دارم یه سیستمی منویسم که شبیه یک وبلاگ
الان تو این سیستم دو نوع دسته بندی برای پست ها دارم
دسته بندی اصلی و فرعی
مدل دسته بندی اصلی کدش اینه تو قسمت ریلیشناش
/**
* @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.
return array(
'postSubGroups' => array(self::HAS_MANY, 'PostSubGroup', 'main_group_id'),
);
}
و کد مدل دسته بندی فرعی عم اینه :
/**
* @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.
return array(
'posts' => array(self::HAS_MANY, 'Post', 'sub_group_id'),
'mainGroup' => array(self::BELONGS_TO, 'PostMainGroup', 'main_group_id'),
);
}
ریلیشن بین این دو دسته بندی اینه که یک دسته بندی اصلی می تونه n تا دسته بندی فرعی داشته باشه
بعد امدم داخل کنترلری که صفحه مدیریت دسته بندی را نشون مده این کدو نوشتم :
/**
* Display PostMainGroup page
*/
public function actionPostSubGroup()
{
$this->render('postSubGroupPage', array(
'pageTitle' => 'مدیریت گروه فرعی پست ها',
'model' => new PostSubGroup,
'part' => 'PostSubGroup',
'baseUrl' => Yii::app()->BaseUrl
)
);
}
و هنگامی که توی view مدیریت دسته بندی ها می خوام یه کمبو بزارم که تمام دسته بندی های اصلی که وارد شدرو نشون بده تا انتخاب منم با ارور مواجه می شم
کد dropdowm اینه :
<?php echo $form->dropDownList(
$model,
'main_group_id',
$model->mainGroup->MainGroupOptions
// 'placeholder' => ' گروه اصلی پست را از این قسمت انتخاب کنید.', 'class'=> 'form-control')
);
و کد تابع getMainGroupOptions که در مدل PostMainGroup هست اینه:
/**
* retrive all maingroup that added to system
* @return array of key=>value maingroup records
*/
public function getMainGroupOptions()
{
$mainGroups = $this->model()->findAll();
return CHtml::listData($mainGroups, 'id', 'name');
}
و توی فایل ویو با error :
Trying to get property of non-object
مواجه می شم کجاش مشکل داره کارم؟
من دارم یه سیستمی منویسم که شبیه یک وبلاگ
الان تو این سیستم دو نوع دسته بندی برای پست ها دارم
دسته بندی اصلی و فرعی
مدل دسته بندی اصلی کدش اینه تو قسمت ریلیشناش
/**
* @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.
return array(
'postSubGroups' => array(self::HAS_MANY, 'PostSubGroup', 'main_group_id'),
);
}
و کد مدل دسته بندی فرعی عم اینه :
/**
* @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.
return array(
'posts' => array(self::HAS_MANY, 'Post', 'sub_group_id'),
'mainGroup' => array(self::BELONGS_TO, 'PostMainGroup', 'main_group_id'),
);
}
ریلیشن بین این دو دسته بندی اینه که یک دسته بندی اصلی می تونه n تا دسته بندی فرعی داشته باشه
بعد امدم داخل کنترلری که صفحه مدیریت دسته بندی را نشون مده این کدو نوشتم :
/**
* Display PostMainGroup page
*/
public function actionPostSubGroup()
{
$this->render('postSubGroupPage', array(
'pageTitle' => 'مدیریت گروه فرعی پست ها',
'model' => new PostSubGroup,
'part' => 'PostSubGroup',
'baseUrl' => Yii::app()->BaseUrl
)
);
}
و هنگامی که توی view مدیریت دسته بندی ها می خوام یه کمبو بزارم که تمام دسته بندی های اصلی که وارد شدرو نشون بده تا انتخاب منم با ارور مواجه می شم
کد dropdowm اینه :
<?php echo $form->dropDownList(
$model,
'main_group_id',
$model->mainGroup->MainGroupOptions
// 'placeholder' => ' گروه اصلی پست را از این قسمت انتخاب کنید.', 'class'=> 'form-control')
);
و کد تابع getMainGroupOptions که در مدل PostMainGroup هست اینه:
/**
* retrive all maingroup that added to system
* @return array of key=>value maingroup records
*/
public function getMainGroupOptions()
{
$mainGroups = $this->model()->findAll();
return CHtml::listData($mainGroups, 'id', 'name');
}
و توی فایل ویو با error :
Trying to get property of non-object
مواجه می شم کجاش مشکل داره کارم؟