1

我的代码上有这个功能,并给我这个错误:

syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ')' on line 25

我找不到错误,也许您可​​以看到我看不到的内容 D:

public function InsertHero()
    {
        $this->load->view('Header');
        $this->load->view('HeroForm');
        $this->load->view('Footer');

        $data = array(
        'Name' -> $this -> input -> post('nick'), //this is the line 25
        'Power' -> $this -> input -> post('superpower'),
        'Phone' -> $this -> input -> post('phone'),
        'Email' -> $this -> input -> post('mail'),
        'Category' -> $this -> input -> post('category_id')
        );
        $this->model_heroes->insert($data);
        redirect(base_url());
    }
4

2 回答 2

1

根据鲁尼的评论,你做一个这样的数组:

array( "foo" => "bar");

不是这个:

array( "foo" -> "bar");
于 2015-09-03T15:00:10.800 回答
1

简单的错误,您在数组声明中使用了类/对象的运算符(T_OBJECT_OPERATOR 是->),而您应该使用 T_DOUBLE_ARROW =>运算符。

因此你的数组应该是这样的;

$data = array('Name' => $this->input->post('nick'));

供参考PHP 运算符

于 2015-09-03T15:02:55.370 回答