Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Secure Files: securing personal files


Go to End
Reply


22 Posts   3055 Views

Avatar
Cano

Community Member, 14 Posts

1 November 2010 at 11:35pm

Edited: 01/11/2010 11:41pm

Thanks very much for getting back to me, I have added in another closing bracket that seemed to be throwing a spanner in the works so the code now shows,

$result->push(new ArrayData(array('Folder' => $folder['Folder'], $files => $files)));

I am now getting the following error message,

[User Error] Bad class to singleton() - Files
GET /silverstripe/investor-login/investor-area/

Line 334 in C:\wamp\www\silverstripe\sapphire\core\Core.php
Source

325 *
326 * @param string $className
327 * @return Object
328 */
329 function singleton($className) {
330    global $_SINGLETONS;
331    if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
332    if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
333    if(!isset($_SINGLETONS[$className])) {
334     if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
335       $_SINGLETONS[$className] = Object::strong_create($className,null, true);
336       if(!$_SINGLETONS[$className]) user_error("singleton() Unknown class '$className'", E_USER_ERROR);
337    }
338    return $_SINGLETONS[$className];
339 }
340

Trace

* Bad class to singleton() - Files
Line 334 of Core.php
* singleton(Files)
Line 2714 of DataObject.php
* DataObject::get(Files)
Line 22 of InvestorPage.php
* InvestorPage->getFilesUserCanAccess()
* call_user_func_array(Array,Array)
Line 693 of Object.php
* Object->__call(getFilesUserCanAccess,Array)
* InvestorPage_Controller->getFilesUserCanAccess()
Line 112 of ViewableData.php
* ViewableData->__get(FilesUserCanAccess)
Line 371 of ViewableData.php
* ViewableData->obj(FilesUserCanAccess)
Line 6 of .cacheC..wamp.www.silverstripe.themes.Vitruvian.templates.Layout.InvestorPage.ss
* include(C:\WINDOWS\Temp\silverstripe-cacheC--wamp-www-silverstripe\.cacheC..wamp.www.silverstripe.themes.Vitruvian.templates.Layout.InvestorPage.ss)
Line 420 of SSViewer.php
* SSViewer->process(InvestorPage_Controller,Zend_Cache_Frontend_Output)
Line 411 of SSViewer.php
* SSViewer->process(InvestorPage_Controller)
Line 202 of Controller.php
* Controller->handleAction(SS_HTTPRequest)
Line 137 of RequestHandler.php
* RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
* Controller->handleRequest(SS_HTTPRequest)
Line 199 of ContentController.php
* ContentController->handleRequest(SS_HTTPRequest)
Line 184 of ContentController.php
* ContentController->handleRequest(SS_HTTPRequest)
Line 67 of ModelAsController.php
* ModelAsController->handleRequest(SS_HTTPRequest)
Line 281 of Director.php
* Director::handleRequest(SS_HTTPRequest,Session)
Line 124 of Director.php
* Director::direct(/investor-login/investor-area/)
Line 127 of main.php


Any thoughts on the problem?

I really do appreciate your help with this, sorry to keep coming back with fresh problems! (I'm midway through a Lynda course on PHP and im diving in at the deepend here!) However, once i get this sorted, it will be somthing i can use again and again, and hopefully understand how/why im gettign these errors!

Cano.

Avatar
Hamish

Community Member, 712 Posts

2 November 2010 at 9:07am

Yep, that's an easy one. The following line is incorrect:

$files = DataObject::get('Files');

There is no "Files" object, only "File" objects.

Avatar
Digital-Punk.co.uk

Community Member, 51 Posts

10 November 2010 at 10:48am

Hi Hamish

I'm using this code to get secured files and display on the frontend:

function getViewableFiles() {
          $files = new DataObjectSet();
          $folders = DataObject::get('Folder');
          if(!$folders) return $files;
          foreach($folders as $folder)
               if(!$folder->Secured && !$folder->InheritSecured())
               continue;
                if($folder->CanView())
                   if($subFiles = DataObject::get('File', "ClassName != 'Folder' && ParentID = {$folder->ID}"))
               $files->merge($subFiles);
          return $files; // Should contain all files that the member can view.
      }

But I have an issue with this code as it is grabbing only last created folder by ID. It means, if I have 2 different users with 2 separated folders, only one user will see files, because I'm getting only one folder. Where could be a problem?

Best regards
Digital Punk

Avatar
Hamish

Community Member, 712 Posts

10 November 2010 at 11:23am

You seem to be missing braces after the foreach loop. Probably the cause of your problem because it's looping through every folder before moving to the CanView check - so only the last folder in the set gets analysed.

Avatar
Cano

Community Member, 14 Posts

10 November 2010 at 11:46am

Hamish = Legend.

Thanks for helping out Silverstripe beginners, you're an asset to it's uptake.

Avatar
Digital-Punk.co.uk

Community Member, 51 Posts

10 November 2010 at 1:43pm

To Hamish

Thanks for your point! It helped to finalize solution.

Best regards
Digital Punk

Go to Top