From 415ae99b14bf955da1a605c03d6f57cc56a4004e Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 18 Aug 2015 03:52:55 +0200 Subject: [PATCH] New behaviour for register components in models --- bin/padmin | 16 +++++++++------- src/Webmodel.php | 25 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/bin/padmin b/bin/padmin index b66d9a1..cbeb2ec 100755 --- a/bin/padmin +++ b/bin/padmin @@ -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); } diff --git a/src/Webmodel.php b/src/Webmodel.php index 0daa7ec..9c39a5b 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -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;