0

I am new in CakePHP. I wanted to create menu in cakePHP 2.3.9 but when I run the application it gives following warning "rawurlencode() expects parameter 1 to be string, array given [CORE\Cake\Routing\Route\CakeRoute.php, line 506]"

I am giving the complete code here. I can not understand how to eliminate the warning message above.

At first I have created this file at /app/Model/menu.php. Which looks like this

<?php
class Menu extends AppModel {
    var $name = 'Menu';
    var $useTable = false;

    function main ($selected = 'home') {
        return array(
            'divClass' => 'menu',
            'ulClass' => 'menu',
            'tabs' => array(
                    array(
                        'controller' => 'pages',
                        'action' => '',
                        'params' => '',
                        'aClass' => $selected == 'home' ? 'selected' : '',
                        'liClass' => '',
                        'text' => 'Home'
                    ),

                    array(
                        'controller' => 'pages/service',
                        'action' => '',
                        'params' => '',
                        'aClass' => $selected == 'Service' ? 'selected' : '',
                        'liClass' => '',
                        'text' => 'Service'
                    ),

                    array(
                        'controller' => 'pages/user',
                        'action' => '',
                        'params' => '',
                        'aClass' => $selected == 'users' ? 'selected' : '',
                        'liClass' => '',
                        'text' => 'Users'
                    ),
            )
        ); // end return
    } // end Main

 } // end class Menu
?>

Then I have created this file at /app/Controller/MenusController.php. Which looks like this

<?php
class MenusController extends AppController {
var $name = 'Menus';
private $menus;

function beforeFilter () {
    parent::beforeFilter();
    $this->menus[] = array(
                        'name' => 'main',
                        'selected' => 'users'
                    );

 //        $this->set('menuList', $this->menus);
}

function index() {
    $this->menus[] = array(
        'name' => 'users',
        'selected' => 'users'
    );

  $this->set('menuList', $this->menus);  
}

function menus($menus) {
    $output = array();

    foreach ($menus as $menu):
        $output[] = $this->Menu->{$menu['name']}($menu['selected']);
    endforeach;

    return $output;
}

}

?>

Then, this file I have created at /app/View/Elements/menu.ctp, which looks like this

<?php
if (empty($menuList)):
$menuList = array(
                array(
                    'name' => 'main',
                    'selected' => 'home'
                )
            );
endif;

$menus = $this->requestAction(
array(
    'controller' => 'menus',
    'action' => 'menus'
),
array('pass' => array( $menuList))
);

if (! empty($menus)):
foreach ($menus as $menu):
    $tabs = '';
    foreach ($menu['tabs'] as $tab):
        $url = array(
                'controller' => $tab['controller'],
                'action' => $tab['action']
               );
        if (! empty($tab['params'])):
               $url[] = $tab['params'];
        endif;

        $tabs .= $this->html->tag(
            'li',
            $this->html->link(
            $tab['text'],
            $url,
            array('class' => $tab['aClass'])),
            array('class' => $tab['liClass'])
        );
    endforeach;
    echo '<div class="' . $menu['divClass'] . '">
          <div class="container_12">
          <div class="grid_12">' . $this->html->tag('ul', $tabs, array('class' => 
    $menu['ulClass'])) . '</div></div></div>';
    endforeach;
endif;
?>

accept my advance gratitude for help

2
  • We would gladly help if you would post some code along with your error message. Nov 18, 2013 at 5:01
  • I have modified my question by giving the code. I can run the application but can not eliminate the warning message.
    – Masud
    Nov 21, 2013 at 3:09

2 Answers 2

0

Your framework might have a default helper function which uses php's rawurlencode() function by default too. You might want to check the parameters you should pass for $this->html->link() since php's rawurlencode() function accepts only a string as a parameter.

0

Although the documentation says requestAction now supports 'array based cake style URLs' which 'bypass the usage of Router::url()', try passing a string as the first parameter to request action.

For example where you currently have:

array(
  'controller' => 'menus',
  'action' => 'menus'
),

Try:

'menus/menus', 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.