joostvanveen / build-a-cms-with-codeigniter

Source code for the Tutsplus course 'Build a CMS with Codeigniter'
53 stars 55 forks source link

Don't show me class active in homepage #13

Closed devsantoshm closed 6 years ago

devsantoshm commented 6 years ago

Hi sir, I have a problem with this code

`function get_menu($array, $child = FALSE) { $CI =& get_instance(); $str = '';

if (count($array)) {
    $str .= $child == FALSE ? '<ul class="nav navbar-nav">'.PHP_EOL : '<ul class="dropdown-menu">'.PHP_EOL;

    foreach ($array as $item) {
        $active = $CI->uri->segment(1) == $item['slug'] ? TRUE : FALSE;
        //Do we have any children?
        if (isset($item['children']) && count($item['children'])) {
            $str .= $active ? '<li class="dropdown active">' : '<li class="dropdown">';
            $str .= '<a href="'.site_url(e($item['slug'])).'">'.e($item['title']);  
            $str .= ' <b class="caret"></b></a>'.PHP_EOL;
            $str .= get_menu($item['children'], TRUE);
        }
        else {
            $str .= $active ? '<li class="active">' : '<li>';
            $str .= '<a href="'.site_url($item['slug']).'">'.e($item['title']).'</a>';
        }

        $str .= '</li>'.PHP_EOL;
    }

    $str .= '</ul>' . PHP_EOL;
}

return $str;

}`

When I enter the homepage, do not select the start menu as active, maybe it's because in my bd I have:

Table pages id title slug order body parent_id 1 Homepage / 1 otro parrafo 0

I understand that when $active = $CI->uri->segment(1) == $item['slug'] ? TRUE : FALSE; in the uri segment there is a string = $item['slug'] should be as active

but in this case.

How would I do to show me as active in the first menu, if when I enter the home page there is no string to make the comparison?

I'm sorry for bothering you, but I do not know how to solve this...

thanks.

joostvanveen commented 6 years ago
if($item['slug'] == '/' && $CI->uri->segment(1) == false) {
    $active = true;
}
devsantoshm commented 6 years ago

@joostvanveen Hi Sir. thank you, but i have another problem.

I have a problem when I enter the page http://ci-cms.com/article/

An uncaught Exception was encountered Type: ArgumentCountError

Message: Too few arguments to function Article::index(), 0 passed in C:\xampp\htdocs\ci-cms\system\core\CodeIgniter.php on line 532 and exactly 2 expected

Filename: C:\xampp\htdocs\ci-cms\application\controllers\article.php

Line Number: 12

Backtrace:

File: C:\xampp\htdocs\ci-cms\index.php Line: 320 Function: require_once

How can i resolve this problem?

Thanks.