method modelize documentation in bbn\Appui\Database
Returns a database model as bbn\Db::modelize but with options IDs.
function(string $table = '', string $db = '', string $host = '', string $engine = 'mysql')
  {
    $model = null;
    if (!$host) {
      $conn = $this->db;
      $host = $this->db->getConnectionCode();
      $old_db = $conn->getCurrent();
      if (Str::isUid($db)) {
        $db = $this->o->getCode($db);
      }
      if ($db && ($old_db !== $db)) {
        try {
          $conn->change($db);
        }
        catch (\Exception $e) {
          throw new \Exception(X::_("Impossible to use the database")." $db");
        }
      }
      elseif (!$db) {
        $db = $this->db->getCurrent();
      }
    }
    elseif ($db) {
      try {
        $conn = $this->connection($host, $engine, $db);
      }
      catch (\Exception $e) {
        throw new \Exception($e->getMessage());
      }
    }
    if (!$conn || !$conn->check()) {
      throw new \Exception(X::_("Impossible to connect"));
    }
    $table_id = null;
    $table    = $conn->tsn($table);
    $ftable   = $conn->tfn($db.'.'.$table);
    $keys     = function (&$a) use (&$table_id, $table, &$conn) {
      if (\is_array($a['keys'])) {
        array_walk(
          $a['keys'],
          function (&$w, $k) use ($table_id, $table) {
            $w['id_option'] = $this->keyId($k, $table_id);
          }
        );
      }
    };
    $fields   = function (&$a) use (&$table_id, $table, &$conn) {
      if (\is_array($a['fields'])) {
        array_walk(
          $a['fields'],
          function (&$w, $k) use ($table_id, $table) {
            if (!$table_id) {
              throw new \Exception(X::_("Table undefined")." $table");
            }
            $w['id_option'] = $this->columnId($k, $table_id);
            $w['option']    = $w['id_option'] ? $this->o->option($w['id_option']) : [];
          }
        );
      }
    };
    if ($model = $conn->modelize($ftable)) {
      if ($table
          && ($table_id = $this->tableId($table, $db, $host, $engine))
      ) {
        $keys($model);
        $fields($model);
        $model['id_option'] = $table_id;
        $model['option']    = $this->o->option($table_id);
}
      elseif (empty($table)) {
        array_walk(
          $model,
          function (&$w, $k) use (&$table_id, &$keys, &$fields, $host, $engine, $db) {
            $table = $this->db->tsn($k);
            if ($table_id = $this->tableId($table, $db, $host, $engine)) {
              $w['id_option'] = $table_id;
              $w['option']    = $this->o->option($w['id_option']);
              $keys($w);
              $fields($w);
            }
          }
        );
      }
    }
    if (!empty($old_db) && ($old_db !== $db)) {
      $conn->change($old_db);
    }
    return $model;
  }
  Returns a database model as bbn\Db::modelize but with options IDs. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
  
  
    
    
      
        
        
      
    
    
    
      
      
      
      
      
        
          
          
          
          
          
          
          
          
            
              
                
              
            
            
              
              This website uses cookies to ensure you get the best experience on our website.                
                
              
              
                
                
              
             
           
          
          
          
            
            © 2011-2025 
BBN Solutions