简体   繁体   中英

Access variables from actions in YII

I have two functions in my controller. There are few fields in my view(say name, email). When I'm trying to access them from function1 it does not work. It says undefined variable:name (it is also defined in model)

public function function1()
{
    $name= $_POST['name'] //displays error
}

public function actionContact()
{
    $model=new ContactForm;
    if(isset($_POST['ContactForm']))
    {
        $this->function1();
    }
}

If form's html code is autogenerated, try to use $_POST['ContactForm']['name'] . Or, if you really need to call function1 , just pass form as a $model to function1 and use it in OOP manner

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM