Can I save arrays via the saveState method?

Sorry I meant setState. I can’t seem to edit the title to fix.

In UserIdentity.php I have the following:

     public function authenticate()




        foreach ($admins as $u) {



        $this->setState('memberId', $user->memberId);

        $this->setState('adminusers', &$adminUsers);



        fwrite($fh,"Data is ".$x."\n");

The output looks fine. The array contains the correct 3 entries which are


The controller class looks like:

 class FcarcMembersController extends Controller



	public function accessRules()



            $adminusers = $user->getState('adminusers');

            $m = $user->getState('memberId');

            $myFile = "/tmp/artestFile.txt";

            $fh = fopen($myFile, 'w');


            fwrite($fh," A Data is ".$x."\n");

            fwrite($fh," R Data is ".$m."\n");

However the output from these write statements show the memberId is OK but the

output from the print_r is "1". It seems that the array was only temporarily

stored in the setState while a string is permanent.

I’m guessing I’m doing something foolish, but I can’t figure out what. Suggestions? The api documentation for setState is rather sparse. I didn’t know if I needed to dereference the $adminUsers array or not, but I tried it both ways with identical results.



It’s because you are passing the array by reference &$adminUsers… so this works as long as $adminUsers has values…

try with

$this->setState('adminusers', $adminUsers);

NOTE: without the &

I had tried it without the & originally and it didn’t work. However it must have been something else I corrected in the mean time, 'cause it works now.

To expand on your comment that it works as long as the array has values, if it is empty, anonymous users can access anything. Don’t ask how I found that out. ;)