Q:

Array to string conversion error using HtmlHelper

<?php
    $radifHa = array();
    foreach ($akhbars as $akhbar) {
        $radif = array();
        $radif[] = $this->Html->tag('h4', h($akhbar['Akhbar']['onvan']));
        $radifInfo = array();
        $radifInfo[] = h($akhbar['Akhbar']['created']);
        $radifInfo[] = $this->Html->tag('span', ':', array('class' => 'separator'));
        $radifInfo[] = 'by';
        $radifInfo[] = $this->Html->link($akhbar['User']['esmekochak'], array('controller' => 'users', 'action' => 'view', $akhbar['User']['id']));
        $radifInfo[] = $this->Html->tag('span', ':', array('class' => 'separator'));
        $radifInfo[] = '0 comments';
        $radif[] = array(implode(' ', $radifInfo), array('class' => 'post_info'));
        $radif[] = $this->Html->div('desc_block', h($akhbar['Akhbar']['kholase']));
    }

    $radifHa[] = $radif;

    if (!empty($radifHa)) {
       echo $this->Html->div('blog_post', h($radifHa));
   }
?>

I'm getting this error
Notice (8): Array to string conversion [CORE\Cake\View\Helper\HtmlHelper.php, line 928]

How can I fix this?
I'm in the index view of Akhbar.
Fixing with this alternative code, but I want to fix with the above code, can I?
<?php foreach ($akhbars as $akhbar): ?>
    <div class="blog_post">
        <h4><?php echo h($akhbar['Akhbar']['onvan']);?></h4>
        <div class="post_info">
        <?php echo h($akhbar['Akhbar']['created']);?>
        <span class="separator">:</span>
        By:<?php echo $this->Html->link($akhbar['User']['esmekochak'], array('controller' => 'users', 'action' => 'view', $akhbar['User']['id']));?>
        <span class="separator">:</span>
        0 comments
        </div>
        <div class="desc_block"><?php echo h($akhbar['Akhbar']['kholase']); ?></div>
    </div>
    <?php endforeach; ?>

A:

You're not telling us exactly what line gives you that error (in the view, not the helper), but the error itself does tell you a lot about what is happening. You are simply passing an array where a string should be passed.
Html->div accepts Html->div(string, string, array), and you are doing
echo $this->Html->div('blog_post', h($radifHa));

Now, . The h() function says

string|array|object   $text   Text to wrap through htmlspecialchars.
  Also works with arrays, and objects. Arrays will be mapped and have
  all their elements escaped. Objects will be string cast if they
  implement a __toString method. Otherwise the class name
  will be used.

You are passing an array to h(), you will get a mapped array with the element escaped. You can see the code for that function here. Line 177, it returns an array. An since Html->div doesn't like arrays as second parameters, well, it complains.
What can you do? Don't use an array. Either flatten the array yourself before using div, or organize that string some other way instead of in an array (like concatenating the resulting strings in a foreach instead of storing them in $radifHa).

