Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 :-)



17.3k
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.phalconphp.com/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.



17.3k
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