PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] Use base_url with a model function

 February 19, 2022     codeigniter, html, php     No comments   

Issue

I'm a rookie on codeigniter and I'm trying to solve a problem where I try to get some images from the database using a foreach cicle

I have this on my controller to get the images

$data['products'] = '.base_url('$this->Cart_model->get_img()').';

and this on my model

    public function get_img()
    {
        $sql  = "SELECT image FROM products";
        $query = $this->db->query($sql); 
        return $query->result_array();
    }

In my view it get me a syntax error beacause something is wrong in the controller

Already checked the View.tpl and everything is fine, must be something in the controller


Solution

You forgot the concatenation operator to concatenate the strings.

$data['products'] = '.base_url(' . $this->Cart_model->get_img() . ').';


Answered By - Alex Karshin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing