Question

Hi what im asking I suppose is quite straight forward, just having problems displaying images in the HTML helper for cakePHP im trying to use the nested array method in cake to arrange the images nicely but keeps giving this error 'Parse error: syntax error, unexpected T_STRING, expecting ')' in C:\wamp\www\end\app\View\Layouts\default.ctp on line 50' heres the code if someone can help me out will be deeply appreciated. PS: im using cake 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);

   ?>
Was it helpful?

Solution

Your code syntax is wrong,

$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'))
                            )
                  )
             );

You cannot use echo inside the array.

Alternatively you can create your own helper and method, as mentioned below:

send only image name array to the helper and in return get name and alt tags in desired order then loop them as shown below:

 $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']));
        }

Hope it will help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top