• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use anything as a rule and $this->some_model issue

#5
UPDATE:

I tested again an it seems to be working perfectly if you call a validation array too. Angry 
The only difference with my live example (which throws 'T_VARIABLE' parse error on $this) is that I assign my validation array (cfr. MY_Model - L. Ezell) as the property $validation_rules at the beginning of my extending child class.

PHP Code:
// eg.
Class User_model extends MY_Model
{
 
   protected $table_name 'test_table';
 
   protected $primary_key 'id';
 
   protected $skip_validation false;
 
   protected $protected_attributes = array('submit');

 
   protected $validation_rules   
    array
(
 
       array(
 
           'field' => 'cn',
 
           'label' => 'Common name',
 
           'rules' => 'required'
 
       ),
 
       array(
 
           'field' => 'birthdate',
 
           'label' => 'Birth Date',
 
           'rules' => [
 
                          'required',
 
                          [
 
                          'birthdate_callable', [ $this'checkdateformat' ]
 
                          ]
 
                      ]
 
       ),
 
       array(
 
           'field' => 'remark',
 
           'label' => 'Remark',
 
           'rules' => 'required'
 
       )
 
   );
 
   }


 
   public function __construct()
 
   {
 
       //parent::__construct();
 
       $this->load->database();

 
   }

...



Now I found this thread: 'Can't concatenate on an array' and the proposed solution was that you have to assign such arrays (containing concanations and even methods starting with $this->) in a method...

So I changed my code (assigned the array in the constructor) to:
PHP Code:
Class User_model extends MY_Model
{
 
  protected $table_name 'test_table';
 
  protected $primary_key 'id';
 
  protected $skip_validation false;
 
  protected $protected_attributes = array('submit');

 
  protected $validation_rules = array();

 
  
   
public function __construct()
 
  {
 
      $this->load->database();
 
      $this->validation_rules 
 
          array(
 
              array(
 
                 'field' => 'cn',
 
                  'label' => 'Common name',
 
                  'rules' => 'required'
 
              ),
 
              array(
 
                  'field' => 'birthdate',
 
                  'label' => 'Birth Date',
 
                  'rules' => [
 
                                 'required',
 
                                 ['birthdate_callable'
 
                                     $this'checkdateformat' ]
 
                                 ]
 
                             ]
 
             ),
 
             array(
 
                  'field' => 'remark',
 
                  'label' => 'Remark',
 
                  'rules' => 'required'
 
            )

 
         );
 
  }

...



 And YES: the problem was solved ...

Does anyone has an explanation for this?

Best regards,

Zeff
Reply


Messages In This Thread
RE: Use anything as a rule and $this->some_model issue - by Zeff - 02-02-2018, 05:40 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.