Exemplo n.º 1
0
 private function facade()
 {
     $crud = new Crud($this);
     $config = $crud->config();
     $facade = isAke($config, 'facade', false);
     $facade2 = false;
     if (false === $facade) {
         $facade = ucfirst($this->db) . ucfirst($this->table);
         if ($this->db == SITE_NAME) {
             $facade2 = ucfirst($this->table);
         }
     }
     $class = '\\Dbjson\\' . $facade;
     if (!class_exists($class)) {
         $code = 'namespace Dbjson; class ' . $facade . ' extends Facade { public static $database = "' . $this->db . '"; public static $table = "' . $this->table . '"; }';
         eval($code);
         Alias::facade('Db' . $facade, $facade, 'Dbjson');
     }
     if (false !== $facade2) {
         $class2 = '\\Dbjson\\' . $facade2;
         if (!class_exists($class2)) {
             $code2 = 'namespace Dbjson; class ' . $facade2 . ' extends Facade { public static $database = "' . $this->db . '"; public static $table = "' . $this->table . '"; }';
             eval($code2);
             Alias::facade('Db' . $facade2, $facade2, 'Dbjson');
         }
     }
 }
Exemplo n.º 2
0
 function updateAction()
 {
     $table = request()->getTable();
     $id = request()->getId();
     if (!is_null($table) && !is_null($id)) {
         $permission = $table . '_json_update';
         $auth = auth()->can($permission);
         if (true === $auth || true === $this->isAdmin) {
             $crud = new c(jmodel($table));
             if (true === $this->isPost()) {
                 $pk = jmodel($table)->pk();
                 $_POST[$pk] = $id;
                 $status = $crud->form();
                 if (true === $status) {
                     $this->forward('list');
                 }
             }
             $infos = $crud->config();
             $singular = isAke($infos, 'singular', 'item');
             $this->view->title = 'Mettre à jour - ' . $singular;
             $this->view->singular = $singular;
             $this->view->fields = $crud->fields();
             $this->view->fieldsInfos = isAke($infos, 'fields');
             $this->view->pk = $crud->pk();
             $this->view->row = jmodel($table)->find($id);
             if (empty($this->view->row)) {
                 $this->forward('home', 'static');
             }
         } else {
             $this->forward('forbidden', 'static');
         }
     } else {
         $this->forward('home', 'static');
     }
 }