CodeIgniter Forums
Get config item in model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Get config item in model (/showthread.php?tid=64496)



Get config item in model - vertisan - 02-25-2016

Like in subject, I need to get some values from config. Normally I using
PHP Code:
$this->config->item'MyOption' ); 

but in model (normal file and MY_Model) I getting
Code:
Parse error: syntax error, unexpected '$this' (T_VARIABLE) ...

Where is my bad?


RE: Get config item in model - solidcodes - 02-25-2016

Can you show us the codes how did you load the model?


RE: Get config item in model - pdthinh - 02-25-2016

Does your models extend CI_Model?


RE: Get config item in model - Diederik - 02-25-2016

You probably forgot to put a semicolon after the previous line/statement.


RE: Get config item in model - vertisan - 02-26-2016

PHP Code:
class Notification_model extends ENC_Model {

    protected 
$SectionTable $this->config->item'TableSections' );

    public function 
__construct() {
        
parent::__construct();
    }

    public function 
GetSectionsList() {

        return 
$this->GetList$this->SectionTable )->result();
        
    }





RE: Get config item in model - salain - 02-26-2016

Hi,

$this object can not be use out of a method.

PHP Code:
class Notification_model extends ENC_Model {

 
   protected $SectionTable;

 
   public function __construct() {
        
$this->SectionTable $this->config->item('TableSections');
 
       parent::__construct();
 
   



RE: Get config item in model - kilishan - 02-26-2016

A few thoughts:

1. Make sure that ENC_Model extends CI_Model, so that it will reference the global controller instance when you try to access something you don't have.
2. Or change that line to get_instance()->config->item('TableSections');
3. Or pass that config setting into the model from the controller or library that calls it.