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']){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥20 求一个简易射频信号综测仪
  • ¥15 esp8266 tally灯 接收端改为发射端
  • ¥30 Labview代码调用access 数据库,相同代码其中一个调用不出来是为什么
  • ¥15 基于51单片机的交通灯系统,找改程序有点急
  • ¥15 java启动jar包后,运行过程中宕机
  • ¥15 进行LM运算过程中出现了无法识别的问题,具体问题如下图
  • ¥500 高有偿提问!求优化设计微信小程序
  • ¥15 matlab在安装时报错 无法找到入口 无法定位程序输入点
  • ¥15 Android Studio webview 的使用问题, 播放器横屏全屏
  • ¥15 删掉jdk后重新下载,Java web所需要的eclipse无法使用
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部