Welcome Guest, Not a member yet? Register   Sign In
Controller validation works, Config/Validation - Syntax error
#1

(This post was last modified: 05-19-2020, 09:03 AM by BilltheCat.)

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

(This post was last modified: 05-19-2020, 11:00 AM by jreklund.)

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




Theme © iAndrew 2016 - Forum software by © MyBB