dpli36193 2013-12-13 12:16
浏览 16

不要在Internet浏览器中打印信息,因为CodeIgniter方法

I have a problem in this method produtos_categoria the model folder, was to print all the information that is in the database, but that is not what happens. He behaves as if there was no information from the database table produtos.

 public function produtos_categoria($categoria){            
        $this->db->where('id_categoria',$categoria);        
        return $this->db->get('produtos')->result();
    }

in my database there are some tables, one of them is the Categorias table and the Produtos table.

I created a method to print the information from the category table and the Products table, but only information appears on the table categories browser. I messed up something in the project and need to find the error, I'm new to PHP programming.

this class is to be created produtos_categoria the method;

<?php

class Categorias_model extends CI_Model{

    var $id_categorias;
    var $categoria_nome;
    var $categoria_slug;
    var $data_alteracao;

    function __construct() {
        parent::__construct();
    }
    public function listar_categorias(){
        return $this->db->get('categorias')->result();
    }
    public function produtos_categoria($categoria){         
        $this->db->where('id_categoria',$categoria);        
        return $this->db->get('produtos')->result();
    }

    public function detalhes_categoria_by_slug($slug){
        $this->db->where('categoria_slug',$slug);
        $categorias = $this->db->get('categorias')->result();
        if(count($categorias) == 1){
            foreach ($categorias as $categoria){
                $this->id_categorias = $categoria->id_categorias;
                $this->categoria_nome = $categoria->categoria_nome;
                $this->categoria_slug = $categoria->categoria_slug;
                $this->data_alteracao = $categoria->data_alteracao;
            }

            $dados['categoria'] = $this;
            $dados['produtos_categoria']= $this->produtos_categoria($this->id_categorias);


        }
        else{
            $dados['categoria']= null;
            $dados['produtos_categoria']= null;
        }

        return $dados;
    } 

}

and this class that this line of code that prints the information in the browser

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

class Home extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Categorias_model','categorias');
    }

    public function index()
    {
        $dados_header = array(
                    'titulo' => 'Super loja legal - Home',
                    'descricao' => 'descrição que vai no cabeçalho html',
                    'palavras_chave' => 'palavra 1,palavra 2, palavra N'
                ); 
                $dados_cabecalho = array(
                    'titulo_h2' => 'Catálago de produtos'
                );

                $dados_cabecalho['categorias'] = $this->categorias->listar_categorias();

                $this->layout->region('html_header','view_html_header',$dados_header);
                $this->layout->region('cabecalho','view_cabecalho',$dados_cabecalho);
                $this->layout->region('corpo','view_conteudo');
                $this->layout->region('rodape','view_rodape');
                $this->layout->region('html_footer','view_html_footer');
                $this->layout->show('layout');



    }
        public function categoria($slug){
            $dados_cabecalho['categorias'] = $this->categorias->listar_categorias();
            $dados['categoria'] = $this->categorias->detalhes_categoria_by_slug($slug);
            echo "<pre>";
            print_r($dados_cabecalho);
            print_r($dados);

        }
}

is this piece of code that prints the information;

public function categoria($slug){
            $dados_cabecalho['categorias'] = $this->categorias->listar_categorias();
            $dados['categoria'] = $this->categorias->detalhes_categoria_by_slug($slug);
            echo "<pre>";
            print_r($dados_cabecalho);
            print_r($dados);

here is the result;

http://localhost/Carrinho_de_Compras/index.php/home/categoria/algum-slug-de-categoria

be returning as if it had no information on the bank;

[categoria] => Array
        (
            [categoria] => 
            [produtos_categoria] => 
        )

)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图