CodeIgniter Forums
Class Properties with Prefixes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Class Properties with Prefixes (/showthread.php?tid=23443)



Class Properties with Prefixes - El Forum - 10-11-2009

[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



Class Properties with Prefixes - El Forum - 10-11-2009

[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 ;
    }



Class Properties with Prefixes - El Forum - 10-11-2009

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


Class Properties with Prefixes - El Forum - 10-11-2009

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