0

i'm litte confuse about this, so i wanna make one function which called menu_function.

for what? so all file php in view, will load this menu_function

this menu_function will load menu option in each php file in view, so it will load different menu option in different php file in view

what i'm think is like this

public function menu_function()
{
    $dataV["menu"] = "<a href='profit' style='color:blue; font-size: 14px; font-weight: bold;'>Profit PT</a>";
    $dataV["menu1"] = "<a href='profit/member' style='color:blue; font-size: 14px; font-weight: bold;'>Profit Member</a>";
    $this->load->view("test", $dataV);
}

i think is bad having html tag in controller or i already read this, according that is efficient i make another php in view just for menu option and load in another view?

why i want to make this? so in future if i wanna add another menu option or remove 1 or more menu option just change in 1 file, not having open all view and remove menu option 1 by 1.

maybe another suggest? thanks

Community
  • 1
  • 1
Pentolan
  • 161
  • 11

1 Answers1

0

What I would do is to create a templates folder inside the views directory, and put there view files that you may require from several controllers. /application/views/templates

Let's name that file header.php and it would look like this

<a href='<?php echo site_url('profit'); ?>' style='color:blue; font-size: 14px; font-weight: bold;'>Profit PT</a>
<a href='<?php echo site_url('profit/member); ?>' style='color:blue; font-size: 14px; font-weight: bold;'>Profit Member</a>

Then, you could include this template in every controller you would want

$this->load->view('templates/header');

Also, for future reference, if you want a function to be available in different controllers you can:

  1. Extend the CI_Controller core class.

    class MY_Controller extends CI_Controller { public function __construct() { parent::__construct(); } /* define here all the functions you want */ }

    Then you would create your controllers extending MY_Controller instead of CI_Controller whenever you would want to call the functions.

  2. Use helpers, libraries and drivers.

Dacklf
  • 700
  • 4
  • 15