• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get value column where column in codeigniter 3

#1
Question 
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.
Reply

#2
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;
?>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
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"
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.