Luc
Luc

Reputation: 63

Is this Codeigniter 3.0 compatible?

Can someone tell me if this code is codeigniter 3.0 compatible ? If not, how should it be formatted?

if ( ! function_exists('get_site_url'))
{
    function get_site_url($data){
        $CI =& get_instance();
        //$data = '';
        //echo base_url(); exit;
        $data =str_replace('{SITE_URL}',base_url(),$data);
        return $data;
    }
}

Upvotes: 0

Views: 74

Answers (2)

Joydeep Dutta
Joydeep Dutta

Reputation: 9

As you pass the $data['common_row'] into the view section
$this->load->view('home_view',$data) the data has been converted into a array is not object so when you are trying to get the data in the view you can try something like this <?php echo get_site_url($common_row['services']);?> or <?php echo get_site_url($common_row[0]['services']);?> depending upon the result.

You can debug the code and see the actual value by

print_r($common_row); die(); on the view page.

Upvotes: 0

Hikmat Sijapati
Hikmat Sijapati

Reputation: 6994

SITE_URL is constant that you define using define('SITE_URL','value').So no need quotes ''.Try like this..

if ( ! function_exists('get_site_url'))
 {
function get_site_url($data){
    $CI =& get_instance();
    //$data = '';
    //echo base_url(); exit;
    $data =str_replace(SITE_URL,base_url(),$data);
    return $data;
}
}

In order to use base_url() don't forget to load url helper in application/config/autoload.php

Upvotes: 1

Related Questions