从数据库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; ?>