Welcome Guest, Not a member yet? Register   Sign In
nav dont working properly
#1
Question 
(This post was last modified: 01-30-2024, 05:22 PM by derose.)

Hello, i already know the problem but i dont know how to fix
in the app/Views i have the layouts/blog/partials which contains the header and footer outside the partials i have the main file which load the layout, in the header i am trying to set my navbar like this:


Code:
<nav class="tm-nav" id="tm-nav">
            <ul>
                <li class="tm-nav-item <?= (uri_string() === '') ? 'active' : ''; ?>">
                    <a href="<?= base_url('') ?>" class="tm-nav-link">
                        <i class="fas fa-home"></i>
                        Inicio
                    </a>
                </li>
                <?php if (isset($post)) : ?>
                    <?php
                        $ultimoPost = end($post);
                        $ultimoPostId = isset($ultimoPost['post_id']) ? (string) $ultimoPost['post_id'] : '';
                        $ultimoPostURI = 'post/' . $ultimoPostId;
                        $currentURI = uri_string();
                    ?>
                    <li class="tm-nav-item <?= (strpos($currentURI, $ultimoPostURI) !== false) ? 'active' : ''; ?>">
                        <a href="<?= base_url($ultimoPostURI); ?>" class="tm-nav-link">
                            <i class="fas fa-pen"></i>
                            Último Post
                        </a>
                    </li>   
                <?php endif; ?>     
                <li class="tm-nav-item <?= (uri_string() === 'sobre') ? 'active' : ''; ?>">
                    <a href="<?= base_url('sobre') ?>" class="tm-nav-link">
                        <i class="fas fa-user"></i>
                        Quem Sou
                    </a>
                </li>
                <li class="tm-nav-item <?= (uri_string() === 'contato') ? 'active' : ''; ?>">
                    <a href="<?= base_url('contato') ?>" class="tm-nav-link">
                        <i class="fas fa-comments"></i>
                        Contato
                    </a>
                </li>
            </ul>
        </nav>


but the problem is, in my controller if i dont set in every function like this:

PHP Code:
$postModel = new PostModel();
$data = [
    "title"=> "Post",
    "post"=> $postModel->find($id),
]; 


the navbar doesnt work like is suppost to work, the thing i am thinking why this is happening is because i am passing the $post variavel inside the header.php who goes inside of every file of my views, but i dont know how to avoid that and fix to work like i want is in this:


Code:
<li class="tm-nav-item <?= (uri_string() === 'post/'.id) ? 'active' : ''; ?>">
    <a href="<?= base_url('post/'.id); ?>" class="tm-nav-link">
       <i class="fas fa-pen"></i>
         Último Post
     </a>                 
</li> 

the id is just an example, in the base url i want to go to the last id of my table post
pls everyone can correct me and give me some solution ?
Reply


Messages In This Thread
nav dont working properly - by derose - 01-30-2024, 05:16 PM
RE: nav dont working properly - by InsiteFX - 01-31-2024, 05:38 AM
RE: nav dont working properly - by wdeda - 02-01-2024, 10:12 AM
RE: nav dont working properly - by InsiteFX - 02-02-2024, 01:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB