Enhance skeleton

This commit is contained in:
Laurent Destailleur 2014-08-17 18:37:33 +02:00
parent b58f6b36a8
commit b6ff6527bc
2 changed files with 11 additions and 7 deletions

View File

@ -134,9 +134,10 @@ class Skeleton_Class extends CommonObject
* Load object in memory from the database * Load object in memory from the database
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Ref
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch($id) function fetch($id,$ref='')
{ {
global $langs; global $langs;
$sql = "SELECT"; $sql = "SELECT";
@ -145,7 +146,8 @@ class Skeleton_Class extends CommonObject
$sql.= " t.field2"; $sql.= " t.field2";
//... //...
$sql.= " FROM ".MAIN_DB_PREFIX."mytable as t"; $sql.= " FROM ".MAIN_DB_PREFIX."mytable as t";
$sql.= " WHERE t.rowid = ".$id; if ($ref) $sql.= " WHERE t.ref = '".$ref."'";
else $sql.= " WHERE t.rowid = ".$id;
dol_syslog(get_class($this)."::fetch"); dol_syslog(get_class($this)."::fetch");
$resql=$this->db->query($sql); $resql=$this->db->query($sql);

View File

@ -62,6 +62,8 @@ if ($user->societe_id > 0)
//accessforbidden(); //accessforbidden();
} }
if (empty($action) && empty($id) && empty($ref)) $action='create';
// Load object if id or ref is provided as parameter // Load object if id or ref is provided as parameter
$object=new Skeleton_Class($db); $object=new Skeleton_Class($db);
if (($id > 0 || ! empty($ref)) && $action != 'add') if (($id > 0 || ! empty($ref)) && $action != 'add')
@ -290,7 +292,7 @@ if ($action == 'create')
// Part to edit record // Part to edit record
if ($id && $action == 'edit') if (($id || $ref) && $action == 'edit')
{ {
dol_fiche_head(); dol_fiche_head();