diff --git a/src/CoreFields/I18nField.php b/src/CoreFields/I18nField.php
index 846c983..094b212 100644
--- a/src/CoreFields/I18nField.php
+++ b/src/CoreFields/I18nField.php
@@ -13,6 +13,7 @@ namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaI18n\I18n;
use PhangoApp\PhaModels\Forms\MultiLangForm;
+use PhangoApp\PhaModels\CoreFields\SlugifyField;
/**
* Multilanguage fields.
@@ -46,7 +47,7 @@ class I18nField extends PhangoField {
settype($value, 'array');
- foreach(PhangoVar::$arr_i18n as $lang_item)
+ foreach(I18n::$arr_i18n as $lang_item)
{
settype($value[$lang_item], 'string');
@@ -58,7 +59,7 @@ class I18nField extends PhangoField {
if($this->required==1 && $value[I18n::$language]=='')
{
- $this->std_error=PhangoVar::$lang['common']['error_you_need_this_language_field'].' '.I18n::$language;
+ $this->std_error=I18n::lang('common', 'error_you_need_this_language_field', 'Error, you need this language field').' '.I18n::$language;
return '';
diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php
index 8d91adb..633119f 100644
--- a/src/CoreFields/PrimaryField.php
+++ b/src/CoreFields/PrimaryField.php
@@ -2,7 +2,7 @@
namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaUtils\Utils;
-use PhangoApp\PhaModels\Forms\BaseForm;
+use PhangoApp\PhaModels\Forms\HiddenForm;
/**
* PrimaryField is used for primary keys for models
@@ -34,7 +34,7 @@ class PrimaryField extends PhangoField {
* By default, the form used for this field is HiddenForm.
*/
- public $form='PhangoApp\PhaModels\Forms\BaseForm';
+ public $form='PhangoApp\PhaModels\Forms\HiddenForm';
/**
* By default this field is protected.
diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php
index f23218d..30eb094 100644
--- a/src/CoreFields/TextHTMLField.php
+++ b/src/CoreFields/TextHTMLField.php
@@ -26,7 +26,7 @@ class TextHTMLField extends PhangoField {
{
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
- $this->multilang=$multilang;
+
$this->set_safe_html_tags();
}
diff --git a/src/Forms/HiddenForm.php b/src/Forms/HiddenForm.php
new file mode 100644
index 0000000..5666b6e
--- /dev/null
+++ b/src/Forms/HiddenForm.php
@@ -0,0 +1,25 @@
+type='hidden';
+
+ }
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/src/Forms/MultiLangForm.php b/src/Forms/MultiLangForm.php
index da6a8f8..962c8cc 100644
--- a/src/Forms/MultiLangForm.php
+++ b/src/Forms/MultiLangForm.php
@@ -9,22 +9,33 @@ use PhangoApp\PhaView\View;
class MultiLangForm extends BaseForm{
- public $type_form='PhangoApp\PhaModels\Forms\BaseForm';
+ public $type_form;
+ public function __construct($name, $value)
+ {
+
+ $this->type_form=new BaseForm($name, $value);
+
+ parent::__construct($name, $value);
+
+ }
+
public function form()
{
+
//make a foreach with all langs
//default, es_ES, en_US, show default if no exists translation for selected language.
+ /*
foreach(I18n::$arr_i18n as $lang_select)
{
- /* $arr_selected[Utils::slugify($lang_select)]='hidden_form';
- $arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form';*/
+ $arr_selected[Utils::slugify($lang_select)]='hidden_form';
+ $arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form';
- /*settype($arr_values[$lang_select], 'string');
+ settype($arr_values[$lang_select], 'string');
echo '
';
echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]);
- echo '
';*/
+ echo '';
}
?>
@@ -182,28 +193,128 @@ class MultiLangForm extends BaseForm{
return $text_form;
*/
- }
-
- function setform($value)
- {
- if(!gettype($value)=='array')
+ if(!get_class($this->type_form))
{
-
- settype($arr_value, 'array');
-
- $arr_value = @unserialize( $value );
+
+ throw new \Exception('Error: need set the $type_form property with a valid class form in '.$this->name);
+
+ }
+
+ if(gettype($this->default_value)!='array')
+ {
+
+ $arr_values=unserialize($this->default_value);
- return $arr_value;
-
}
else
{
+
+ $arr_values=$this->default_value;
+
+ }
+
+ //print_r($this->default_value);
+
+ foreach(I18n::$arr_i18n as $lang_select)
+ {
+
+ $slug=Utils::slugify($lang_select);
+ $lang_slug=Utils::slugify(I18n::$language);
+
+ $arr_selected[$slug]='hidden_form';
+ $arr_selected[$lang_slug]='no_hidden_form';
+
+ $this->type_form->name=$this->name.'['.$lang_select.']';
+
+ $this->type_form->default_value=$this->setform($arr_values[$lang_select]);
+
+ echo '';
+ echo $this->type_form->form();
+ echo '
';
+
+ }
+
+ ?>
+
+
+
; ?>)
+
+
+
+
+
+
+ name=Utils::slugify($this->name);
ob_start();
diff --git a/src/Webmodel.php b/src/Webmodel.php
index 0ddd3d7..acd5618 100644
--- a/src/Webmodel.php
+++ b/src/Webmodel.php
@@ -276,8 +276,24 @@ class Webmodel {
static public $arr_sql_unique=array();
static public $arr_sql_set_unique=array();
+ /**
+ * Simple property for save models in object mode
+ */
+
static public $m;
+ /**
+ * A simple array for load js, header and css from forms objects only one time
+ */
+
+ static public $form_type=array();
+
+ /**
+ * A simple array for control if was loaded contents from a form
+ */
+
+ static public $form_type_checked=array();
+
//Construct the model
/**
@@ -1552,36 +1568,49 @@ class Webmodel {
{
//With function for create form, we use an array for specific order, after i can insert more fields in the form.
-
- $this->forms=array();
- $arr_form=array();
-
- if(count($fields_form)==0)
- {
-
- $fields_form=array_keys($this->components);
-
- }
-
- foreach($fields_form as $component_name)
- {
-
- if(isset($this->components[$component_name]))
- {
-
+ $this->forms=array();
+
+ $arr_form=array();
+
+ if(count($fields_form)==0)
+ {
+
+ $fields_form=array_keys($this->components);
+
+ }
+
+ foreach($fields_form as $component_name)
+ {
+
+ if(isset($this->components[$component_name]))
+ {
+
if($this->components[$component_name]->label=='')
{
$this->components[$component_name]->label=ucfirst($component_name);
}
-
+
$this->create_form($component_name);
- }
+ }
- }
+ }
+
+
+ foreach(array_keys(Webmodel::$form_type) as $type)
+ {
+ $type::js();
+ $type::css();
+ $type::header();
+
+ Webmodel::$form_type_checked[$type]=1;
+
+ }
+
+ Webmodel::$form_type=array();
}
@@ -1599,6 +1628,15 @@ class Webmodel {
$this->forms[$component_name]=new $form_class($component_name, $component->value);
+ $type_class=get_class($this->forms[$component_name]);
+
+ if(!isset(Webmodel::$form_type_checked[$type_class]))
+ {
+
+ Webmodel::$form_type[$type_class]=1;
+
+ }
+
$this->forms[$component_name]->default_value=$component->default_value;
$this->forms[$component_name]->required=$component->required;
$this->forms[$component_name]->label=$component->label;