本文整理匯總了PHP中common\models\Category::getCategoriesById方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::getCategoriesById方法的具體用法?PHP Category::getCategoriesById怎麽用?PHP Category::getCategoriesById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類common\models\Category
的用法示例。
在下文中一共展示了Category::getCategoriesById方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionUpdate
/**
* Updates an existing Post model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->unlinkAll('categories', true);
foreach (Category::getCategoriesById($model->categories_id) as $category) {
$model->link('categories', $category);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
$model->categories_id = ArrayHelper::getColumn($model->categories, 'id');
return $this->render('update', ['model' => $model]);
}
}
示例2: actionUpdate
/**
* Updates an existing Post model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
/** @var Post $model */
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->unlinkAll('categories', true);
foreach (Category::getCategoriesById($model->categories_id) as $category) {
$model->link('categories', $category);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
/** @var Category $category */
foreach ($model->categories as $category) {
if ($category->active) {
$model->categories_id[] = $category->id;
}
}
return $this->render('update', ['model' => $model]);
}
}