Profile Subpage Error

Permalink 2 users found helpful
I added a subpage named Purchases under the main Profile page in my site (created single page /profile/purchases). The page shows up fine but when I include the call to the profile sidebar I get the following error:
Fatal error: Call to a member function getUserID() on a non-object in .../updates/concrete5.4.1.1/concrete/elements/profile/sidebar.php on line 4.
Here's the code of my purchases.php single page (basically just copied the profile view page and modified it a little):
<?php  defined('C5_EXECUTE') or die("Access Denied."); ?>
<div id="ccm-profile-wrapper">
    <?php Loader::element('profile/sidebar', array('profile'=> $profile)); ?>    
    <div id="ccm-profile-body">   
       <p><a href="/profile" title="">&larr; Back to Your Profile</a></p>
       <div id="ccm-profile-body-attributes">
        <h2><?php echo t('My Purchases')?></h2>
      </div>
      <?php  
         $a = new Area('Main'); 
         $a->setAttribute('profile', $profile); 
         $a->setBlockWrapperStart('<div class="ccm-profile-body-item">');
         $a->setBlockWrapperEnd('</div>');
         $a->display($c); 
      ?>

If I comment out the Loader:element 'profile/sidebar' line the page loads fine, but the profile sidebar doesnt show up obviously.
Anyone have any ideas as to what the problem is and how to fix it?

 
Shotster replied on at Permalink Reply
Shotster
Well, that seems like it should work, but try the following instead...

Rename your purchases.php to view.php and put it here...

/single_pages/profile/purchases/view.php

-Steve
Shotster replied on at Permalink Reply
Shotster
Forget that. It's not going to work. You had it set up properly.

The problem is that the variable $profile is not initialized for reasons which aren't clear to me at this point.

-Steve
Shotster replied on at Permalink Best Answer Reply
Shotster
> The problem is that the variable $profile is not initialized
> for reasons which aren't clear to me at this point.

Now I remember why! You have to create a controller for your single page. Here's how...

Copy the core controllers/profile/controller.php

...to...

/controllers/profile/purchases.php

Edit that controller and change the class name to...

ProfilePurchasesController

I think that should do it.

-Steve
c5mix replied on at Permalink Reply
Steve,
That did the trick! Works perfectly now. Thanks a million!

If anyone from the core team is seeing this - this page in the docs should be updated to mention that you have to do this, under the section 'Adding a Page to the Public Profile':
http://www.concrete5.org/documentation/developers/permissions/profi...
Mnkras replied on at Permalink Reply
Mnkras
Look at the guest views plugin, blocks->login->templates->profile_sidebar.php that should show you how to do it,