Aynı model içinde Array Put başka 1 İşlev değişken geçmek için çalışılıyor

3 Cevap php

Tamam, bu gerçekten kafa karıştırıcı geliyor. Ne yapmaya çalışıyorum bu. Ben yüklenenler / sunucu fotoğrafları boyutlandırır bir işlevi var. Bu DB yollarını saklayan. Ben fotoğraf satır iş id eklemek gerekir.

İşte ben bugüne kadar ne var:

function get_bus_id() {
    $userid = $this->tank_auth->get_user_id();
    $this->db->select('b.id');
    $this->db->from ('business AS b');
    $this->db->where ('b.userid', $userid);
    $query = $this->db->get();
        if ($query->num_rows() > 0) {
          // RESULT ARRAY RETURN A MULTIDIMENSIONAL ARRAY e.g. ARRAY OF DB RECORDS
          // ( ROWS ), SO IT DOENS'T FIT
          //return $query->result_array();
          // THE CORRECT METHOD IS row_array(), THAT RETURN THE FIRST ROW OF THE 
          // RECORDSET
          $query->row_array();
            }

Yani olsun iş kimliği bulunuyor. Sonra, aşağıda benim yükleme işlevi vardır:

/* Uploads images to the site and adds to the database. */
    function do_upload() {

        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->gallery_path,
            'max_size' => 2000
        );

        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();

        $config = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $this->gallery_path . '/thumbs',
            'maintain_ratio' => true,
            'width' => 150,
            'height' => 100
        );

        $this->load->library('image_lib', $config);
        $this->image_lib->resize();

        $upload = $this->upload->data();
        $bus_id = $this->get_bus_id();

        $data = array(
            'userid' => $this->tank_auth->get_user_id(),
            'thumb' => $this->gallery_path . '/thumbs/' . $upload['file_name'],
            'fullsize' => $upload['full_path'],
            'busid'=> $bus_id['id'],
        );

        echo var_dump($bus_id);

        $this->db->insert('photos', $data);
    }

Ben alıyorum sorun şudur:

Bir PHP hata ile karşılaşıldı

Önem: Bildirimi

Mesaj: Undefined index: id

Dosya Adı: modelleri / gallery_model.php

Satır sayısı: 48

Ben değeri üzerinden almak için yollar her türlü denedim, ama benim sınırlı bilgim şekilde olmaya devam ediyor. Herhangi bir Yardım gerçekten takdir.

3 Cevap

değil bir "cevap" göndererek olmadan size bir soru sormak nasıl emin ...

48 hattı içinde ne var? gallery_model.php hangi dosya? bunun sesler, o henüz başlatılmamış bir dizi anahtarı veya veritabanı sorgulama bir sorun olabilir.

Sorun iş bulunmazsa, sizin fonksiyon şey dönüyor olmasıdır. Sonuç olarak, $bus_id (onun bile bir dizi), bir şey var. Muhtemelen get_bus_id() function şöyle return false olmalıdır:

        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }

Eğer $bus_id == false sonra aramak sonra get_bus_id() kontrol edebilirsiniz ve belki do_upload() bir hata belirtmek için return false

Tamam, ben çalışma var. Bu tam ve çalışma kodu:

/* Uploads images to the site and adds to the database. */
    function do_upload() {

        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->gallery_path,
            'max_size' => 2000
        );

        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();

        $config = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $this->gallery_path . '/thumbs',
            'maintain_ratio' => true,
            'width' => 150,
            'height' => 100
        );

        $this->load->library('image_lib', $config);
        $this->image_lib->resize();

        $upload = $this->upload->data();
        $bus_id = $this->get_bus_id();

        /*
        TABLE STRUCTURE =============
            id, the row ID
            photoname
            thumb
            fullsize
            busid
            userid
        */



        $data = array(
            'id'        => 0 , // I GUESS IS AUTO_INCREMENT
            'photoname'    => '',
            'thumb'        => $this->gallery_path . '/thumbs/' . $upload['file_name'],
            'fullsize'    => $upload['full_path'],
            'busid'=> $bus_id['id'],
            'userid' => $this->tank_auth->get_user_id(),
        );

        // CHECK THE DATA CREATED FOR INSERT

        $this->db->insert('photos', $data);
    }

/ / DB İşletme kimliği alın

function get_bus_id() {
        $userid = $this->tank_auth->get_user_id();
        $this->db->select('b.id');
        $this->db->from ('business AS b');
        $this->db->where ('b.userid', $userid);
        $query = $this->db->get();
            if ($query->num_rows() > 0) {
              // RESULT ARRAY RETURN A MULTIDIMENSIONAL ARRAY e.g. ARRAY OF DB RECORDS
              // ( ROWS ), SO IT DOENS'T FIT
              //return $query->result_array();
              // THE CORRECT METHOD IS row_array(), THAT RETURN THE FIRST ROW OF THE
              // RECORDSET
              return $query->row_array();
            }
        }