douzhun8615 2019-05-08 15:09
浏览 70
已采纳

在我调用函数的控制器上使用模型函数的可变数据

So I have a website where I buy items. I do an if to see if the session data "moedas" (user's coins) is greater than or equal to the item's price. I want to get the item's data from my model where I have the model's function dados_acessorio. So I call this function on my controller and what I want is to receive that data and be able to use it on the same controller after. The problem is I am getting an error. I am new to php/CodeIgniter and I could use some help.

Here is the controller's function:

public function confirmarCompra($id){

     $this->load->model('acessorios_model','acessorios');
     $dados['acessorio'] = $this->acessorios->dados_acessorio($id)[0];

     if($this->session->moedas >= $acessorio['preco']){


     }
}

Here is the model's function:

public function dados_acessorio($id){

            return $this->db->from('acessorios')->where('id_acessorio', $id)->get()->result_array();
}

Here is an image of my acessorios table:

https://imgur.com/tth9mKS

The error that I receive on the controller:

https://imgur.com/BdR2ZMq

The error is on the following line: if($this->session->moedas >= $acessorio['preco'])

Thanks!

  • 写回答

1条回答 默认 最新

  • douwen2072 2019-05-08 17:25
    关注

    Looks like it could be a typo? $acessorio is how it will appear in the view.

    change this:

    if($this->session->moedas >= $acessorio['preco']){
    

    to this

    if($this->session->moedas >= $dados['acessorio']['preco']){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了