douzhun8615 2019-05-08 23: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-09 01: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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么