We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

mkdir after $user-save(); with user ID

Hi,

how can i make a dir after user is save, with the actual user ID?

This is my code:

            if ($user->save()) {
                mkdir("../clients/". $this->request->getPost('id', 'int') . "/", 0777);                    
                return $this->dispatcher->forward(array(
                    'controller' => 'index',
                    'action' => 'index'
                ));
            }

Thx again :-)



60.0k
Accepted
answer
edited Sep '15

Ok i got it :-))))))

                if ($user->save()) {
                    mkdir("../clients/". $user -> id."/", 0777);
                    return $this->dispatcher->forward(array(
                        'controller' => 'index',
                        'action' => 'index'
                    ));
                }

Make a mkdir("../clients/". $user -> id."/", 0777); in every request is too bad performance wise.

edited Sep '15

Maybe check it if not exists before create ? I guess its only created only if $user is created

Maybe use the afterCreate event https://docs.phalcon.io/en/latest/reference/models.html#events-and-events-manager

Also, if you have many servers, you would need to rethink how this directory will be created or synced across servers.



60.0k
edited Sep '15

Hi Jurigag and Andres,

Thank you for your advice.

I am using Vokuro as my base system and the mkdir ist set in the registerAction.

My question is:

Isn't it so, that the Auth checks if an user exists or not?

If not exists, it will be create an user and the dir, and if exists the dir will not be created.

But myabe i have a flaw.

Rgds

Stefan