New behaviour for register components in models

This commit is contained in:
Antonio de la Rosa 2015-08-18 03:52:55 +02:00
parent fe66a759d5
commit 415ae99b14
2 changed files with 28 additions and 13 deletions

View file

@ -14,8 +14,11 @@ else
use PhangoApp\PhaModels\SQLClass;
use PhangoApp\PhaModels\Webmodel;
use PhangoApp\PhaUtils\Utils;
use League\CLImate\CLImate;
Utils::load_config('config');
$options=getopt('', array('model:'));
padminConsole($options);
@ -32,9 +35,9 @@ function padminConsole($options)
//echo "Use: php console.php -m=padmin -c=padmin --model=module/model\n";
$climate->white()->backgroundBlack()->out("Use: padmin --model=module/model");
$climate->white()->backgroundBlack()->out("Use: padmin --model=path/to/model");
die;
exit(0);
}
@ -43,16 +46,16 @@ function padminConsole($options)
settype($arr_option[0], 'string');
settype($arr_option[1], 'string');
Webmodel::$model_path='./modules/';
#Webmodel::$model_path='./modules/';
$model_file=Webmodel::$model_path.$arr_option[0].'/models/models_'.$arr_option[1].'.php';
$model_file=$options['model'].'.php';
if(!is_file($model_file))
{
$climate->white()->backgroundRed()->out("Error: cannot find the model file in ".$arr_option[0]."/models/models_".$arr_option[1].".php");
die();
exit(1);
}
@ -68,8 +71,7 @@ function padminConsole($options)
} catch(Exception $e)
{
$climate->white()->backgroundRed()->out($e->getMessage());
//echo $e->getMessage()."\n";
die;
exit(1);
}

View file

@ -3,6 +3,7 @@
namespace PhangoApp\PhaModels;
use PhangoApp\PhaI18n\I18n;
use PhangoApp\PhaModels\CoreFields\PrimaryField;
/**
* The most important class for the framework
@ -265,7 +266,7 @@ class Webmodel {
$this->name=$name_model;
$this->idmodel='Id'.ucfirst($this->name);
$this->components[$this->idmodel]=new \PrimaryField();
$this->components[$this->idmodel]=new PrimaryField();
$this->label=$this->name;
if(!isset(Webmodel::$connection_func[$this->db_selected]))
@ -277,8 +278,6 @@ class Webmodel {
$this->cache=$cache;
$this->type_cache=$type_cache;
}
@ -1097,6 +1096,17 @@ class Webmodel {
return SQLClass::webtsys_query($sql_query);
}
/**
* Method used for update tables
*/
public function update_table()
{
}
/**
@ -1582,11 +1592,14 @@ class Webmodel {
* @param string $arguments Array with arguments for construct the new field
* @param boolean $required A boolean used for set the default required value
*/
public function register($name, $type, $arguments, $required=0)
public function register($name, $type_class, $required=0)
{
$rc=new \ReflectionClass($type);
$this->components[$name]=$rc->newInstanceArgs($arguments);
/*$rc=new \ReflectionClass($type);
$this->components[$name]=$rc->newInstanceArgs($arguments);*/
$this->components[$name]=&$type_class;
//Set first label...
$this->components[$name]->label=Webmodel::set_name_default($name);
$this->components[$name]->name_model=$this->name;