public function posts() { $posts = Model::getAll('Blog\\Model\\Post'); foreach ($posts as $post) { $post->author = Model::get('Blog\\Model\\User', $post->user_id)->name; } $this->render('Post/list', ['posts' => $posts]); }
public function form($id = null) { if ($this->get('submit')) { $user = new UserModel(); $user->id = $id; $user->name = $this->get('name'); Model::save($user); return $this->redirect('users'); } $user = $id ? Model::get('Blog\\Model\\User', $id) : new UserModel(); $this->render('User/form', ['user' => $user]); }
public function form($id = null) { $category = $id ? Model::get('Blog\\Model\\Category', $id) : new CategoryModel(); $form = new CategoryForm($id, $category->name); return $this->render(['form' => $form, 'category' => $category]); }
public function form($id = null) { $model = $id ? Model::get($this->model, $id) : new $this->model(); $form = new $this->form($id, $model->name); return $this->render(['form' => $form, $this->single => $model]); }