public function editAction($id) { $id = (int) $id; $form = new ProjectForm(); $model = Project::findFirst($id); if ($this->request->isPost()) { $form->bind($this->request->getPost(), $model); if ($form->isValid()) { if ($model->save()) { $this->uploadImage($model); $this->flash->success('Информация обновлена'); return $this->redirect('/projects/admin/edit/' . $model->getId()); } else { $this->flashErrors($model); } } else { $this->flashErrors($form); } } else { $form->setEntity($model); } $this->view->model = $model; $this->view->form = $form; $this->view->title = 'Редактирование проекта'; }
public function projectAction() { $id = (int) $this->dispatcher->getParam('id', 'int'); $imagePos = (int) $this->request->getQuery('image', 'int', 1); $project = Project::findFirst(array("id = {$id} AND visible = '1'", array('cache' => array('key' => md5("Project::findById({$id})"), 'lifetime' => 60)))); if (!$project) { throw new Exception("Project ID = {$id} not found"); } $projectImage = ProjectImage::find(array("conditions" => "project_id = {$id}", "order" => "id ASC", "limit" => array("number" => 1, "offset" => $imagePos - 1))); $this->helper->title()->append($project->getTitle()); $this->helper->title()->append('Галерея проектов'); $this->view->imagePos = $imagePos; $this->view->project = $project; $this->view->projectImage = $projectImage[0]; }