Jump to content

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.