Example #1
0
 public function form($id = null)
 {
     if ($this->get('submit')) {
         $post = new Post();
         $post->id = $id;
         $post->title = $this->get('title');
         $post->content = $this->get('content');
         $post->user_id = $this->get('user_id');
         $post_id = Model::save($post);
         Model::delete('Blog\\Model\\PostCategory', $post_id, 'post_id');
         foreach ($this->get('categories') as $category) {
             $post_category = new Model\PostCategory();
             $post_category->category_id = $category;
             $post_category->post_id = $post_id;
             Model::save($post_category);
         }
         return $this->redirect('posts');
     }
     $post = $id ? Model::get('Blog\\Model\\Post', $id) : new Post();
     $post_categories = Model::getAll('Blog\\Model\\PostCategory', 'post_id', $id);
     $post_categories_ids = [];
     foreach ($post_categories as $post_category) {
         $post_categories_ids[] = $post_category->category_id;
     }
     $this->render(['post' => $post, 'users' => Model::getAll('Blog\\Model\\User'), 'categories' => Model::getAll('Blog\\Model\\Category'), 'post_categories' => $post_categories_ids]);
 }
Example #2
0
 public function save($id = null)
 {
     $form = new $this->form($id, $this->request->get('name'));
     if ($form->validate($this->request)) {
         $model = new $this->model();
         $model->id = $id;
         $model->name = $this->request->get('name');
         Model::save($model);
         return Response::redirect($this->single . '/index');
     }
     return Response::redirect($this->single . '/edit/' . $id);
 }
Example #3
0
 public function save($id = null)
 {
     $form = new CategoryForm($id, $this->request->get('name'));
     if ($form->validate($this->request)) {
         $category = new CategoryModel();
         $category->id = $id;
         $category->name = $this->request->get('name');
         Model::save($category);
         return Response::redirect('category/index');
     }
     return Response::redirect('category/edit/' . $id);
 }
Example #4
0
 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]);
 }