簡體   English   中英

從數據庫PHP Codeigniter加載圖像

[英]Loading images from database php codeigniter

我試圖從數據庫中加載圖像,我可以獲取完整的字符串,並且圖像上不顯示任何內容,當我使用完整的數組時,會收到數組消息。

這是模型:

public function get_webstore($webstore_id = '') {
        /* get video */
        if (empty($webstore_id)) {
            $webstores = $this->get('webstore');
        } else {
            $webstores = $this->get('webstore', $webstore_id);
        }

        $webstore_array = array();
        foreach ($webstores as $webstore) {


            $singleWebstorePair = array();
            if (!empty($webstore['images'])) {
                $allWebstores = unserialize($webstore['images']);
                foreach ($allWebstores as $allWestores) {
                    $singleWebstorePair[] = str_replace("./", "", base_url($allWebstores));
                }
            }
            $webstore_array[] = array(
                'id' => $webstore['id'],
                'title' => $webstore['title'],
                'content' => $webstore['content'],
                'images' => $singleWebstorePair,
                'created' => $webstore['created']
            );
        }
        return $webstore_array;
    }

這是前端代碼

<div class="col-md-12" style="height: 225px;">
                <div class="col-md-4 text-center thumbnail123">
                    <img class="thumbnail" width="225px" src="<?php echo $webstore['images']?>.jpg"/>
                    <h3><?php echo $webstore['title']; ?></h3> 
                    <p>Date Added: <?php echo date('d-m-y', strtotime($webstore['created'])) ?></p>
                     <hr>

                    <hr>
                </div>

如果需要,這里是控制器:

   public function __construct() {
        parent::__construct();
        $this->load->model("post");
        $this->load->database();
        $this->load->helper("url");


    }
    public function index() {

    $this->data['posts'] = $this->post->get_webstore($limit=null, $offset=null); // calling Post model method getPosts()
    $this->data['page_title'] = 'Store';
    $this->layout("pages/webstore", $this->data);

和錯誤:

Severity: Notice

Message: Array to string conversion

Filename: pages/webstore.php

Line Number: 45

多謝你們

填充數組時,設置為數組的'images' => $singleWebstorePair,˙

在您的模板中,您正在呼應:

<img class="thumbnail" width="225px" src="<?php echo $webstore['images']?>.jpg"/>

但是這里$webstore['images']是一個數組。 因此,如果$webstore['images']擁有多個圖像源,則循環遍歷它:

<?php foreach($webstore['images'] as $image) : ?>
   <img class="thumbnail" width="225px" src="<?php echo $image ?>.jpg"/>
<?php endforeach; ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM