public function insert()
 {
     if ($this->Session->user('role') == 'admin') {
         if (isset($this->request['name'])) {
             $validation = new CategoriesDao($this->request);
             if ($validation->valide('insert')) {
                 $save = new Categories();
                 $save->insert($validation);
                 $cache = new Cache();
                 $cache->purge_all();
                 $this->redirection('categorie/admin');
             } else {
                 if (isset($validation->error)) {
                     foreach ($validation->error as $k => $v) {
                         echo '<br>' . $v;
                     }
                 }
             }
         }
         $this->render('edit', 'Categories', 'admin');
     } else {
         $this->redirection('');
     }
 }
 public function insert()
 {
     if ($this->Session->user('role') == 'admin') {
         if (isset($this->request['name'])) {
             $this->request['pathimg'] = $_FILES['pathimg']['name'];
             $validation = new PostsDao($this->request);
             if ($validation->valide('insert')) {
                 $dir = $this->baseDir2 . '/web/img/' . $_FILES['pathimg']['name'];
                 $resultat = move_uploaded_file($_FILES['pathimg']['tmp_name'], $dir);
                 $save = new Posts();
                 $save->insert($validation);
                 $cache = new Cache();
                 $cache->purge_all();
                 $this->redirection('posts/admin');
             } else {
                 if (isset($validation->error)) {
                     foreach ($validation->error as $k => $v) {
                         echo '<br>' . $v;
                     }
                 }
             }
         }
         $this->render('edit', 'Posts', 'admin');
     } else {
         $this->redirection('');
     }
 }