试图在select中获取非对象的属性

时间:2017-08-29 13:25:20

标签: codeigniter

遇到PHP错误

严重性:注意

消息:尝试获取非对象的属性

文件名:models / Tournaments_model.php

行号:101

我有这个问题。在我的项目中需要,当我选择一个选项时,我可以选择几个选项

我的模特

function create_new_tournaments($id, $name, $about, $date, $reg_date, $time, $city, $address, $country, $photo, $type)
{
    $maxid = 0;
    //$this->load->database();
    $row = $this->ci->db->query("SELECT MAX(id) AS maxid FROM tournaments")->row();
    if ($row) {
        $maxid = $row->maxid;
    }
    $maxid++;

    // Define data to insert

    $data = array(
        "id"=>$maxid,
        "name" => $name,
        "description" => $about,
        "date" => $date,
        "registration_date" => $reg_date,
        "time" => $time,
        "city" => $city,
        "address" => $address,
        "country" => $country,
        "poster" => $photo,
        "type" => $type,

    );


    // If inserting data fails
    if (!$this->ci->db->insert("tournaments", $data)) {
        // Return false
        return FALSE;
    }

    foreach ($id as $id_categories) {

        $data2 = array(
            "tournament_id" => $maxid,
            "category_id" => $id_categories->id,

        );

        if (!$this->ci->db->insert("tournament_categories", $data2)) {
            // Return false
            return FALSE;
        }
    }

    return TRUE;
}

我的控制员:

$id = $this->input->post('select_categories');

我的观点:

<select class="js-example-basic-multiple form-control" id="select_categories" name="select_categories[]" multiple="multiple">

1 个答案:

答案 0 :(得分:1)

这是一个数组,数组中的元素可以像这样访问

$id_categories['id']

您的$ data2现在是

$data2 = array(
            "tournament_id" => $maxid,
            "category_id" => $id_categories['id'],

        );