Hi

Discovered this awesome framework a little while ago, really nice!

I have created my own MyPHPTAL class in which I add a couple of things to
its context (figured that this would be cleaner that setting them manually
in every php page), works fine except for when I try and add a custom Class
of mine.

I have this in my constructor (actually the complete class) :

require_once("globals.php");
require_once("User.class.php");
require_once("PHPTAL.php");

class MyPHPTAL extends PHPTAL{

    public function __construct($path=false){
        parent::__construct($path);

        if( isset($_SESSION[USER_OBJ]) ){
            $this->set('user', $_SESSION[USER_OBJ] );
            $this->set('hasUser', true);
        }
        else{
            $this->set('hasUser', false);
        }

    }

}

The User class:

require_once('UserRole.class.php');
require_once('UserStatus.class.php');

class User {
    public $id;
    public $fName;
    public $lName;
//cut
}

When I reference the user object in my template like this:

<div tal:content="user/fName" tal:condition="hasUser">The users name</div>

 I get the following error:

exception 'PHPTAL_Exception' with message 'Unable to find part "fName" in
path "fName" with base "object"' in
C:\wamp\my_includes\PHPTAL\Context.php:357 Stack trace: #0
C:\Windows\Temp\tpl_1230913754_1_1_14templatehtaf12aceee0491df97ea1590f2eb17e87.php(80):
phptal_path(Object(__PHP_Incomplete_Class), 'fName')
#1 C:\wamp\my_includes\PHPTAL.php(466):
tpl_1230913754_1_1_14templatehtaf12aceee0491df97ea1590f2eb17e87_page_template(Object(MyPHPTAL),
Object(PHPTAL_Context))
#2
C:\Windows\Temp\tpl_1230911056_1_1_14loginhtmlfc12130e5db631fadfdd3a92f0355c5d.php(45):
PHPTAL->executeMacro('template.html/p...')
#3 C:\wamp\my_includes\PHPTAL.php(386):
tpl_1230911056_1_1_14loginhtmlfc12130e5db631fadfdd3a92f0355c5d(Object(MyPHPTAL),
Object(PHPTAL_Context))
#4 C:\wamp\www\login.php(51): PHPTAL->execute() #5 {main}


The php page using the MyPHPTAL class is calling session_start() at the very
top.

Have been googling this and have found some information indicating that the
session might be started before the User class definition is loaded
preventing it from properly unserialize the it from the session.

I'm more of a Java developer than a PHP one so I'm hoping that you guys can
give me some help :)

Many thanks,
 Micke
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to