Welcome Guest, Not a member yet? Register   Sign In
Codeigniter libraries params
#1

(This post was last modified: 11-11-2022, 05:22 AM by MatrickEganlan.)

Sometime ago i added some params to a library, and it worked just fine ... i dont know if i messed up with some configuration setting or what, right now i cant pass the developerbook chatrandom exact same params.

The library Template:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Template {

        public $config = array();



        public function __construct($params = NULL)
        { 

                echo '<pre>'; print_r($params); echo '</pre>';
                /*This should print the array (and it's printing nothing):

                Array
                (
                    [menus] => Array
                      (
                            [Administradores] => index
                            [Logs] => logs
                      )

                )*/

            if ($params){
                foreach ($params as $key => $value){
                    $this->config[$key] = $value;
                }
            }

        }

        public function cms_template($pagina=NULL, $modulo=NULL, $titulo=NULL, $data=NULL, $dir='backoffice')
        {
            $CI =& get_instance();
            $CI->load->library('session');
            if (isset($this->config['menus']))
                $menus = $this->config['menus'];
            else
                $menus=NULL;

            $dados['dados'] = array(
                'id_administrador' => $CI->session->userdata('id_administrador'),
                'email' => $CI->session->userdata('email'),
                'nome' => $CI->session->userdata('nome'),
                'modulo' => $modulo,
                'titulo' => $titulo,
                'menus' => $menus
            );

            $CI->load->view($dir.'/topo', $dados);
            $CI->load->view($dir.'/'.$pagina, $data);
            $CI->load->view($dir.'/rodape');   
        }
The controller:

public function __construct() {
        parent::__construct();
        $this->auth_model->verificaLogin('id_administrador','backoffice/login');
        $this->load->model('administradores_model');
        $params=array(
            'menus' => array(
                'Administradores'=>'index',
                'Logs'=>'logs'
            )
        );

        $this->load->library('template', $params);
    }
When i run it, it throws me n error on the view:

<?php
            foreach ($dados['menus'] as $key => $value) {
                echo '<li>'.active_anchor('/'.$this->uri->segment(1).'/'.$this->uri->segment(2).'/'.$value, $key, '/'.$this->uri->uri_string()).'</li>';
            }
            ?>
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()
Reply




Theme © iAndrew 2016 - Forum software by © MyBB