Welcome Guest, Not a member yet? Register   Sign In
Get config item in model
#1

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?
Reply
#2

Can you show us the codes how did you load the model?
No SEO spam
Reply
#3

Does your models extend CI_Model?
Reply
#4

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

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();
        
    }


Reply
#6

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();
 
   
Reply
#7

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB