I'm new in CodeIgniter in general. I have a view layout, on which I have navigation menu bar in it. I want to populate the dropdown menu with categories I've saved in database.

Here's snippet of my layout (View\layouts\frontend.php):

```
<nav class="navbar navbar-expand-md sticky-top">
    <div class="collapse navbar-collapse flex-column " id="navbar">
        <!-- Brand bar -->
        <a class="navbar-brand ml-3" href="#">
            <span class="">Test Site</span>
        </a>
        <!-- Internal links Menu navbar -->
        <ul class="navbar-nav justify-content-center w-100 px-3">
            <li class="nav-item">
                <a class="nav-link" href="#">Home</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Categories
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                    <a class="dropdown-item" href="#">News</a>
                    <a class="dropdown-item" href="#">Event</a>
                    <a class="dropdown-item" href="#">Announcement</a>
                </div>
            </li>
        </ul>
</nav>

```

Now, I understand that on every views that Extends that layout, I can just do query on controller and return the view with data. Here's what I've done so far and it works.

Home Controller:

```
use App\Models\CategoryModel;

class Home extends BaseController
{
    public function index()
    {
        $categoryModel = new CategoryModel();
        $data['categories'] = $categoryModel->orderBy('id', 'ASC')->findAll();

        return view('frontend/home_page', $data);
    }
}

```

Part of layout:

```
<li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Categories
    </a>
    <?php if ($categories) : ?>
        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            <?php foreach ($categories as $category) : ?>
                <a class="dropdown-item" href="#"><?php echo $category['name'] ?></a>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
</li>

```

But it looks like I have to do that on all controllers' functions that renders my views that use my layout (frontend.php).
What I want to ask is, is there a possibility to just make a function/class/something to call so it's only done one time? What is the best practice in this situation?
['https://Stackoverflow.com/questions/64256903', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14378974/']
I'd recommend using different classes over inline css.

```css
.heading {
  font-size: 50px;
  font-weight: bold;
  border-bottom: 5px solid black;
}

.heading.morning {
  color: green;
}

.heading.afternoon {
  color: purple;
}

.heading.night {
  color: blue;
}

```

```
if (currentTime < 12 && currentTime >= 0) {
  ReactDOM.render(
    <div>
      <h1 className="heading morning">Good Morning</h1>
    </div>,
    root
  );
} else if (currentTime >= 12 && currentTime <= 18) {
  ReactDOM.render(
    <div>
      <h1 className="heading afternoon">Good Afternoon</h1>
    </div>,
    root
  );
} else {
  ReactDOM.render(
    <div>
      <h1 className="heading night">Good Evening</h1>
    </div>,
    root
  );
}

```
I think that you are not using inline-css - `To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.`. But that is just "definition".

Anyway, what are you doing is not correct. You should create a component (see: <https://reactjs.org/docs/react-component.html>) where you will have logic for the change of color (see: <https://reactjs.org/docs/faq-state.html#what-does-setstate-do> - you can save the color in `state`). Then you can add the `componentDidMount` method and there you can add `setInterval` - so you can basically set "every X hour I will change the color".