使用cakephp3

时间:2016-04-06 16:33:37

标签: php cakephp-3.0

  

使用Cake \ ORM \ TableRegistry;

$ websites => TableRegistry ::得到( '网站');

$ query => $ websites-> find() - > order(['creation_date'=>'DESC']);

  echo "<table>";
    echo"<tr>
           <td>Cover Image</td>
           <td>Company Name</td>
           <td>Date Added</td> 
         </tr>";
    foreach ($query as $row) {
    echo"<tr>
          <td>".$row['Website']['image']."</td>
          <td>".$row->company."</td
          <td>".$row->creation_date."</td>            </tr>";
    }      
 echo"</table>";

?>      
      I remember this code in cakephp2 and display the images path "app/webroot/img/websites/"
    <?php echo $this->Html->image('websites/' . $row['Website']['image']);

但如何在cakephp3中执行此操作,以显示图像。  ?&GT;

2 个答案:

答案 0 :(得分:0)

在cakephp 3中没有任何大的区别,它很简单,如下面的代码

 <?php foreach ($websites as $websites): ?>
    <?= $this->Html->image('websites/'.$websites->image) ?> 
 <?php endforeach; ?>

答案 1 :(得分:0)

您似乎不知道自己的真正问题。您的问题似乎是有人在用正确的HTML代码上传图片时遇到问题。为此,您只需要在数据库表列中为varchar类型指定该上载字段,然后在视图中将图像从文件类型上载至该字段即可。像这样:

<div class="form-group">

       <?php
            echo $this->Form->input('your_column_name', [ 'type' => 'file']); 
        ?>
</Div>

但是,如果您的问题是有关无法检索或发送到index.ctp或前端视图的上载图像,那么您的解决方案就在这里: How to retrieve in cakephp3.7 the name as string of an image uploaded trough a form with blob column into a mysql database?