CodeIgniter Forums

Full Version: How to get value column where column in codeigniter 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a table like:
Code:
sysopt|sysval
......................    
site_url|http://domain.com/
site_title|My Website
......................

in mysql i use:
Code:
$query = $db->query("SELECT * FROM sysconfig");
while ($result = $db->fetch_array($query)) {
   $settings[$result['sysopt']] = $result['sysval'];
}

But in CI:
Code:
class Sysinfo
{
   var $info = array();

public function __construct()
{
   $CI =& get_instance();
   $settings = $CI->db->select("*")
   ->get("sysconfig");
   foreach($settings as $setting) {
       $this->info[$setting['sysopt']] = $setting['sysval'];
   }
}

In view i call:
Code:
<?php echo $this->Sysinfo->info->site_url; ?>

Show error.
Code:
Message: Undefined property: CI_Loader::$Sysinfo

Thankyou any solution fix.
You can try this, but it is not recommended to do in a view it should be done in your controller.

PHP Code:
<?php
    $CI 
= =& get_instance();
 
   echo $CI->this->Sysinfo->info->site_url;
?>
yo

you affect your data directly to $infos array in your controller.

$this->info['site_url'] = 'http://www.google.com';

so why do you call $this->Sysinfo->info->site_url ?

call directly echo $this->info['site_url']; // will show "http://www.google.com"