使用html helper cake在无序列表方法中显示图像

时间:2014-02-14 18:30:30

标签: cakephp-2.3

嗨我问我想是非常直接的,只是在CakePHP的HTML帮助器中显示图像时遇到问题我试图在蛋糕中使用嵌套数组方法很好地排列图像但是一直给出这个错误'解析错误:语法错误,意外的T_STRING,期待')'在第50行的C:\ wamp \ www \ end \ app \ View \ Layouts \ default.ctp'如果有人可以帮助我的话代码将会受到深深的赏识。 PS:我正在使用蛋糕2.3.6。

    <?php echo $this->Html->image('logo.png', array('alt' => 'logo image'));?>
   <?php $list = array(
    'echo $this->Html->image('cloud.png', array('alt' => 'logo image'))' => array(
    'echo $this->Html->image('heart.png', array('alt' => 'logo image'))' => array(
    'echo $this->Html->image('email.png', array('alt' => 'logo image'))',
    'echo $this->Html->image('profile.png', array('alt' => 'logo image'))',
    'echo $this->Html->image('logo.png', array('alt' => 'logo image'))', 

    echo $this->Html->nestedList($list);

   ?>

1 个答案:

答案 0 :(得分:0)

您的代码语法错误,

$list = array(
             $this->Html->image('cloud.png', array('alt' => 'logo image')) =>
             array(
                  $this->Html->image('heart.png', array('alt' => 'logo image')) => 
                        array(
                            $this->Html->image('email.png', array('alt' => 'logo image')),
                            $this->Html->image('profile.png', array('alt' => 'logo image')),
                            $this->Html->image('logo.png', array('alt' => 'logo image'))
                            )
                  )
             );

你不能在数组中使用echo。

或者,您可以创建自己的帮助器和方法,如下所述:

只将图像名称数组发送给帮助程序,然后以所需顺序获取名称和alt标记,然后按如下所示循环它们:

 $list = array('cloud.png','heart.png','email.png','profile.png','logo.png'); 

        $arragedList =  $this->MyHelper->nestedList($list);
        foreach($arragedList as $arrangedImages){
             echo $this->Html->image($$arrangedImages['imageName'], 
                               array('alt' =>$$arrangedImages['altTag']));
        }

希望它会有所帮助!