Welcome Guest, Not a member yet? Register   Sign In
Help migration 3x to 4x
#5

This is not tested! You really should sit down and read the CodeIgniter User Guide.

PHP Code:
<?php

namespace App\Libraries;

use 
Config\Database;

/**
 * Class Menu
 *
 * @package App\Libraries
 */
class Menu
{

    
/**
     * Class properties go here.
     * -------------------------------------------------------------------
     * public, private, protected, static and const.
     */

    
public $listMenus;

    public 
$listSeo;

    
/**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {
        
$this->set();
    }

    
/**
     * set ()
     * -------------------------------------------------------------------
     *
     */
    
public function set()
    {
        
$db      Database::connect();
        
$builder $db->table('users');

        
$query $builder->select('*')
        
                      ->from("menu")
        
                      ->where("parente"0)
        
                      ->where("ativo"1)
        
                      ->orderBy('posicao''asc')
        
                      ->get();

        
$menusPai = ($query->countAllResults() > 0) ? $query->getResultArray() : false;

        
$query2 $builder->select('*')
        
                       ->from("menu")
        
                       ->where("parente > 0")
        
                       ->where("ativo"1)
        
                       ->orderBy('posicao''asc')
        
                       ->get();

        
$menusFilhos = ($query2->countAllResults() > 0) ? $query2->getResultArray() : false;

        
$menus = [];

        foreach (
$menusPai as $key => $value)
        {
            
$this->listSeo[$value['link']]['pagina_titulo']      $value['pagina_titulo'];
            
$this->listSeo[$value['link']]['pagina_keywords']    $value['pagina_keywords'];
            
$this->listSeo[$value['link']]['pagina_description'] = $value['pagina_description'];

            
$menus[$value['id']]['filhos'] = [];
            
$menus[$value['id']]['dados']  $value;

            if (
$menusFilhos)
            {
                foreach (
$menusFilhos as $k => $v)
                {
                    if (
$v['parente'] == $value['id'])
                    {
                        
$this->listSeo[$v['link']]['pagina_titulo']      $v['pagina_titulo'];
                        
$this->listSeo[$v['link']]['pagina_keywords']    $v['pagina_keywords'];
                        
$this->listSeo[$v['link']]['pagina_description'] = $v['pagina_description'];

                        
$menus[$value['id']]['filhos'][] = $v;
                    }
                }
            }
        }

        
$this->listMenus $menus;
    }

    
/**
     * get ()
     * -------------------------------------------------------------------
     *
     * @return mixed
     */
    
public function get()
    {
        return 
$this->listMenus;
    }

    
/**
     * seo ()
     * -------------------------------------------------------------------
     *
     * @param  $tag
     * @return mixed
     */
    
public function seo($tag)
    {
        
$uri = ($this->CI->uri->uri_string() == '') ? '/' $this->CI->uri->uri_string();

        return 
$this->listSeo[$uri][$tag];
    }

    
// -------------------------------------------------------------------

}   // End of Menu Library Class.

/**
 * -----------------------------------------------------------------------
 * Filename: Menu.php
 * Location: ./app/Libraries/Menu.php
 * -----------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
Help migration 3x to 4x - by guilhermepalange - 10-07-2020, 07:11 AM
RE: Help migration 3x to 4x - by guilhermepalange - 10-07-2020, 07:12 AM
RE: Help migration 3x to 4x - by InsiteFX - 10-07-2020, 01:44 PM
RE: Help migration 3x to 4x - by guilhermepalange - 10-07-2020, 05:16 PM
RE: Help migration 3x to 4x - by InsiteFX - 10-08-2020, 03:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB