doulin6448
2014-03-23 09:06 阅读 17
已采纳

从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();
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanba7498 duanba7498 2014-03-23 09:20

    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

    点赞 评论 复制链接分享

相关推荐