This is a really useful line of code I used today whilst working on an app in codeigniter. I wanted to be able to style a few pages differently based on which page in the app I was on and this allowed me to do that easily. Note the use of ‘rsegment’ instead of ‘segment’ becuase I use routes in the app.

<body class="page-<?php echo $this->uri->rsegment(1); ?>-<?php echo $this->uri->rsegment(2); ?>">

This provided a body class that takes the format ‘page-controller-method’. For my app it looked like this:

<body class="page-dashboard-login">

Then in my CSS file I can do this:

.page-dashboard-login {
/* CSS here */