Jump to content

adomingo10

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

0 Comum

About adomingo10

  • Birthday 02/15/1979

Informações Pessoais

  • Sexo
    Masculino
  • Localização
    São Paulo
  • Interesses
    Codeigniter, PHP, MySQL

Contato

  • Hangouts
    adomingo10
  1. adomingo10

    Erro: variável indefinida php codeigniter

    Pessoal Sou iniciante e estou com dúvida no erro de variável indefinida, a conexão do BD funciona, em outra página do projeto os dados são listados corretamente. Nesse código abaixo, já testei de tudo e aparecem dois códigos de erro. O objetivo desse código é listar dentro do html os dados da tabela do BD, exemplo: vou deixar fixo um registro da categoria no topo da página. Código: <!-- CONTROLLER --> <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Buscar extends CI_Controller { public $data = array(); public function __construct(){ parent::__construct(); $this->load->model('menus_model'); $this->data['base_url'] = base_url(); $this->data['menus'] = $this->menus_model->getMenus(); $this->data['menu_ativo'] = ''; $this->data['header'] = $this->load->view('frontend/includes/header.php', $this->data, true); $this->data['navigation'] = $this->load->view('frontend/includes/navigation.php', $this->data, true); $this->data['footer'] = $this->load->view('frontend/includes/footer.php', $this->data, true); } public function index() { //page title $this->data['title'] = 'Buscar'; //template buscar $this->data['body'] = $this->load->view('frontend/pages/buscar.php', $this->data, true); //default template $this->load->view('frontend/templates/default.php', $this->data); } public function search_category(){ $this->load->model("Buscar_model"); $lista = $this->Buscar_model->BuscarCategory(); $dados = array("categories" => $lista); $this->load->view('frontend/pages/buscar.php', $dados); } } // MODEL // <?php class Buscar_model extends CI_Model{ public function getBuscar( $keyword=null ){ if($keyword){ $this->db->like('client_name', $keyword); $this->db->or_like('category_name', $keyword); $this->db->or_like('client_description', $keyword); $this->db->or_like('city_name', $keyword); $this->db->where('client_active', 1); } return $this->db->get("base_clie_total")->result_array(); } public function BuscarCategory(){ return $this->db->get("categories")->result_array(); } } // VIEW // <body> <section class="hero is-info"> <div class="hero-head"> <header class="nav"> <div class="container"> <div class="nav-left"> <a class="nav-item logo" href="<?= $base_url ?>"> <img src="<?= $base_url ?>assets/img/blank.png" alt="Site"> </a> </div> <div class="nav-right nav-menu"> <?= $navigation ?> </div> </div> </header> </div> </section> <section class="section"> <div class="container"> <h2 class="title">Buscar</h2> <?php foreach ($lista as $categ) : ?> <? $categ ['category_name'] ?> <?php endforeach ?> /*/ ERRO 1: /*/ A PHP Error was encountered Severity: Notice Message: Undefined variable: lista Filename: pages/buscar.php Line Number: 26 Backtrace: File: D:\BF\SITE\application\views\frontend\pages\buscar.php Line: 26 Function: _error_handler File: D:\BF\SITE\application\controllers\Buscar.php Line: 30 Function: view File: D:\BF\SITE\index.php Line: 322 Function: require_once /*/ ERRO 2: /*/ A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: pages/buscar.php Line Number: 26 Backtrace: File: D:\BF\SITE\application\views\frontend\pages\buscar.php Line: 26 Function: _error_handler File: D:\BF\SITE\application\controllers\Buscar.php Line: 30 Function: view File: D:\BF\SITE\index.php Line: 322 Function: require_once
×

Important Information

Ao usar o fórum, você concorda com nossos Terms of Use.