Jump to content

Archived

This topic is now archived and is closed to further replies.

smokyyyyyy

Severity: Notice Message: Undefined index: menu

Recommended Posts

HI i am new to progreamming and CodeIgniter I created a new function in CodeIgniter  HTML_HELPER.PHP which can create menu when pass an array in function as parameter

When i run the script it says

 

A PHP Error was encountered

 

Severity: Notice

 

Message: Undefined index: menu

 

Filename: helpers/html_helper.php

 

Line Number: 445

A PHP Error was encountered

 

Severity: Warning

 

Message: Invalid argument supplied for foreach()

 

Filename: helpers/html_helper.php

 

Line Number: 447

A PHP Error was encountered

 

Severity: Notice

 

Message: Undefined variable: li_a_menu

 

Filename: helpers/html_helper.php

 

Line Number: 450

 

Following is my code kindly help me

 

if ( ! function_exists('menu'))
{
function menu($menu=''){
            $id=$menu['id'];
    $item= $menu ['menu'];
    $nav_menu='<div id ='."$id".'>';
    foreach($item as $li_menu){
        $li_a_menu[]='< a href ='.base_url().$li_menu.'>'.strtoupper(str_replace('_','',$li_menu)).'</a>';
            }
            $nav_menu.=ul($li_a_menu).'</div>';
            echo $nav_menu;


}
}

 

I created the View navigtion.php

i am calling it like this

 

$data= array('id'=>'nav', array ('menu1' =>'home',
'menu2' =>'create_post',
'menu3' =>'contact',
'menu4' =>'about'),
);


echo menu($data);


 

It throws error message kindly help me please read the error message at the start of this post

Share this post


Link to post
Share on other sites

The way your function works, your input array needs to be adjusted to this:

 

$data = array('id'=>'nav', 'menu' => array ('menu1' =>'home',
                                         'menu2' =>'create_post',
                                         'menu3' =>'contact',
                                         'menu4' =>'about'),
);

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.