Welcome Guest, Not a member yet? Register   Sign In
Class Properties with Prefixes
#1

[eluser]insub2[/eluser]
I'mtrying to set up a Table Model so that I can change which tables I'm using for the whole application. I have a prefix on some of my tables so I'm trying to do this:
Code:
<?php

class Table_model extends Model
{
    /* Set up Table Aliases
    --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
    var $_prefix = 'beta_';
    var $_user = $_prefix.'user';
    var $_profile = $_prefix.'user_profile';

...etc.

But I get an error:
Quote:Parse error: syntax error, unexpected T_VARIABLE in /home/insub2/Websites/CV_Test/system/application/models/table_model.php on line 8
#2

[eluser]steelaz[/eluser]
You can't do that when declaring variables, add prefix in your constructor instead:

Code:
<?php

class Table_model extends Model
{
    /* Set up Table Aliases
    --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
    var $_prefix = 'beta_';
    var $_user = 'user';
    var $_profile = 'user_profile';

    function __construct()
    {
        parent::__construct();
        
        $this->_user = $this->_prefix . $this->_user;
        $this->_profile = $this->_prefix . $this->_profile ;
    }
#3

[eluser]insub2[/eluser]
Thanks. But why is that? ...just curious.
#4

[eluser]steelaz[/eluser]
It's just how PHP works, it's not related to CodeIgniter.




Theme © iAndrew 2016 - Forum software by © MyBB