• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controller validation works, Config/Validation - Syntax error

#1
Maybe this will be an obvious question, but I can't see what's wrong with it.

If I use this validation rule in my Controller, it works fine.  Doing basically the same thing in Config/Validation, and my IDE gives me a syntax error message

Controller: 
PHP Code:
        // validate form input
        $this->validation->setRules([
            'identity' => [
                'label' => str_replace(':'''lang('Auth.login_identity_label')),
                'rules' => 'required'
                ],
            'password' => [
                'label' => str_replace(':'''lang('Auth.login_password_label')),
                'rules' => 'required'
                ]
        ]); 


Config/Validation:
PHP Code:
public $login = [
            'identity' => [
                'label' => str_replace(':'''lang('Auth.login_identity_label')),
                'rules' => 'required'
                ],
            'password' => [
                'label' => str_replace(':'''lang('Auth.login_password_label')),
                'rules' => 'required'
                ]
        ]; 


Syntax error:
[Image: kGeO1B.jpg]
Reply

#2
That's because it's an variable. You can't execute functions in there. Not specific to CodeIgniter, it's PHP itself.
Reply

#3
(05-19-2020, 09:57 AM)jreklund Wrote: That's because it's an variable. You can't execute functions in there. Not specific to CodeIgniter, it's PHP itself.

Thanks, that's what I thought was happening, as I tried a few variations that also didn't work.

Can you point me to a doc, or even a google search that would give more details? I tried, but I don't know specifically what to search for here.
Reply

#4
Hi, the correct term are Class Properties.
https://www.php.net/manual/en/language.o...erties.php

"This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated."
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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