• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with menu links

#1
[eluser]Unknown[/eluser]
i'm new to Ci, was trying to generate menu links like this in a nav_view.php file:

<?php
$data=array(
'id'=>'nav',
'menus'=>array(
'menu1'=>'home',
'menu2'=>'create_post',
'menu3'=>'contact_us',
'menu4'=>'about_us',
),
);
echo menu($data);

?>

i'm getting this error:
Fatal error: Call to undefined function menu() in C:\wamp\www\myblog\application\views\nav_view.php on line 11

can please tell me how to fix this? or is there a simple way i can use to generate menu links and breadcrumbs?

thanks!

#2
[eluser]TWP Marketing[/eluser]
[quote author="dannie_manji" date="1344538582"]i'm new to Ci, was trying to generate menu links like this in a nav_view.php file:
Code:
<?php
      $data=array(
        'id'=>'nav',
        'menus'=>array(
        'menu1'=>'home',
'menu2'=>'create_post',
'menu3'=>'contact_us',
        'menu4'=>'about_us',
    ),
      );
        echo menu($data);

?>

i'm getting this error:
Fatal error: Call to undefined function menu() in C:\wamp\www\myblog\application\views\nav_view.php on line 11

can please tell me how to fix this? or is there a simple way i can use to generate menu links and breadcrumbs?

thanks![/quote]
First, used the [ code] tags so it is easier for us to read (I've put them in above)
You are calling a function in a view file. The function does not exist here, it should be created in your controller.
Please post the code for your controller (in [ code] tags please) and we can advise you on how to approach this.

#3
[eluser]TWP Marketing[/eluser]
[quote author="TWP Marketing" date="1344540236"][quote author="dannie_manji" date="1344538582"]i'm new to Ci, was trying to generate menu links like this in a nav_view.php file:
Code:
<?php
      $data=array(
        'id'=>'nav',
        'menus'=>array(
        'menu1'=>'home',
'menu2'=>'create_post',
'menu3'=>'contact_us',
        'menu4'=>'about_us',
    ),
      );
        echo menu($data);

?>

i'm getting this error:
Fatal error: Call to undefined function menu() in C:\wamp\www\myblog\application\views\nav_view.php on line 11

can please tell me how to fix this? or is there a simple way i can use to generate menu links and breadcrumbs?

thanks![/quote]
First, used the [ code] tags so it is easier for us to read (I've put them in above)
You are calling a function in a view file. The function does not exist here, it should be created in your controller.
Please post the code for your controller (in [ code] tags please) and we can advise you on how to approach this.[/quote]

I receive this via PM
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends CI_Controller {

public function index()
{
  $this->load->view('header_view.php');
  $this->load->view('nav_view.php');
  $this->load->view('content_view.php');
  $this->load->view('footer_view.php');
  
}
}
You should setup the data array in the controller, something like this:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends CI_Controller {

public function index()
{
  $data = array()
  $data = array(
   'id'=>'nav',
   'menus'=>array(
    'menu1'=>'home',
    'menu2'=>'create_post',
    'menu3'=>'contact_us',
    'menu4'=>'about_us',
    ),
   );
  $this->load->view('header_view.php');
  $this->load->view('nav_view.php',$data); // Pass the data array to the view here
  $this->load->view('content_view.php');
  $this->load->view('footer_view.php');
  
}
}

public function home()
{
somecode here
}

public function create_post()
{
somemore code here
}

public function contact_us()
{
yet more code
}

public function about_us()
{
and some more code
}
...

Your view will have something like this:
Code:
...
echo '<a href="http://yoursite.com/index.php/blog/home">'.$menus['menu1'].'</a>';
echo '<a href="http://yoursite.com/index.php/blog/create_post">'.$menus['menu2'].'</a>';
echo '<a href="http://yoursite.com/index.php/blog/contact_us">'.$menus['menu3'].'</a>';
echo '<a href="http://yoursite.com/index.php/blog/about_us">'.$menus['menu4'].'</a>';
...

This is a bare outline, since I don't know all you wish to accomplish.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.