public function createUrl($manager, $route, $params) { $path = explode('/', $route); if (!isset($path[2])) { return false; } if ($path[0] !== $this->moduleId) { return false; } if (!in_array($path[1], ['article', 'category'])) { return false; } if (!in_array($path[2], ['view', 'update', 'delete', 'create'])) { return false; } if (!$this->pretty) { if (isset($params['model'])) { $id = $params['model']->id; } else { $id = $params['id']; } return $route . '?id=' . $id; } $params['path'] = NULL; if (isset($params['model'])) { if (!$params['model'] instanceof Article && !$params['model'] instanceof Category) { throw new NotSupportedException("Unsupported entity: " . get_class($params['model'])); } if (!$params['model']->path) { Module::checkPathes(); $params['model']->genPath(); } $params['path'] = $params['model']->path; } if (!isset($params['path']) && !strlen($params['path'])) { if (!isset($params['id'])) { return false; } for ($i = 0; $i < 2; $i++) { $id = intval($params['id']); if ($path[1] == 'article') { $table = 'articles_article'; } else { $table = 'articles_category'; } $entity = \Yii::$app->db->createCommand("SELECT path FROM {{%{$table}}} WHERE id='{$id}'")->cache(60)->queryOne(); if ($entity['path']) { break; } Module::checkPathes(); } $params['path'] = $entity['path']; } $url = $params['path']; if ($path[2] !== 'view') { $url .= '?action=' . $path[2]; } return $url; }
/** * Updates an existing Category 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()) { Module::checkPathes(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }
public function actionIndex() { Module::checkPathes(); return $this->render('index'); }