Doh!

As feared it was a simple misstake, for some reason I thought I had to call
session_start() at the very beginning. Moving session_start() until after
the classes have bean loaded solved the problem.




2009/1/3 Mikael Andersson <mail.mi...@gmail.com>

> Hi
>
> Just tried to add a __autoload but still can't get it to work.
>
> If I do a var_dump on the object from the session that I put into the
> context, it looks like this:
>
> object(__PHP_Incomplete_Class)#1 (13) {
>
>   ["__PHP_Incomplete_Class_Name"]=>
>   string(4) "User"
>   ["id"]=>
>   string(1) "1"
>   ["fName"]=>
>   string(6) "Mikael"
>   ["lName"]=>
>
>   string(9) "Andersson"
>   ["uName"]=>
>   string(5) "micke"
>   ["email"]=>
>   string(20) "mail.mi...@gmail.com"
>
>   ["regDate"]=>
>   string(19) "2009-01-02 10:01:08"
>   ["role"]=>
>   string(1) "1"
>   ["status"]=>
>   string(1) "1"
>   ["phoneNumber"]=>
>
>   string(6) "123456"
>   ["secretQuestion"]=>
>   string(0) ""
>   ["secretAnwser"]=>
>   string(0) ""
> }
> Error:Unable to find part "fName" in path "fName" with base "object"
>
> Have a feeling that I'm missing something simple (like in my previous
> mailing list topic :) ), so any suggestion no matter how obvious is welcome.
>
> - Micke
>
> 2009/1/2 Mikael Andersson <mail.mi...@gmail.com>
>
> Hi Levi,
>> thanks for you reply.
>>
>> Updated MyPHPTAL.class.php to look like this:
>> <?php
>> 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);
>>         }
>>
>>     }
>>
>>     public function render(){
>>         // execute the template
>>         try {
>>             echo $this->execute();
>>         }
>>         catch (Exception $e){
>>             echo $e;
>>         }
>>     }
>>
>> }
>> ?>
>> And my controller code looks like this:
>>
>> <?php
>> session_start();
>> require_once("../lib/globals.php");
>> require_once("../lib/sec_check.php");
>> require_once("../lib/MyPHPTAL.class.php");
>>
>> // create a new template object
>> $template = new MyPHPTAL("home.html");
>>
>> // put some data into the template context
>> $template->title = 'Hem';
>>
>> $template->render();
>>
>> ?>
>>
>> But I'm still getting the same error for my own custom User class.
>>
>> The "hasUser" variable and "title" variable both work fine.
>>
>> Grateful for any suggestions,
>>  Micke
>>
>> 2009/1/2 Levi Stanley <l...@eneservices.com>
>>
>> Forgot to mention
>>>
>>> $controller->render() doesn't exist in PHPTAL, so just do the try catch
>>> print execute stuff you normally do.
>>>
>>>
>>> Levi Stanley wrote:
>>> > If your controller code is doing something like this:
>>> >
>>> > <?php
>>> >
>>> >     session_start();
>>> >     include_once('MyPHPTAL.php');
>>> >
>>> >
>>> >     $controller = new MyPHPTAL('main-page.xhtml');
>>> >     $controller->set('other_variables', 2.23);
>>> >     $controller->render();
>>> >
>>> > ?>
>>> >
>>> > There shouldn't be a problem at all.
>>> >
>>> > Best regards,
>>> > Levi Stanley
>>> >
>>> > Mikael Andersson wrote:
>>> >> 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
>>> >>
>>> >
>>>
>>>
>>> _______________________________________________
>>> PHPTAL mailing list
>>> PHPTAL@lists.motion-twin.com
>>> http://lists.motion-twin.com/mailman/listinfo/phptal
>>>
>>
>>
>
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to