Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I access the slim properties from the templates? #62

Open
NeftaliAcosta opened this issue Mar 8, 2020 · 2 comments
Open

Can I access the slim properties from the templates? #62

NeftaliAcosta opened this issue Mar 8, 2020 · 2 comments

Comments

@NeftaliAcosta
Copy link

Through my API I already have a route that receives parameters and creates users, this works perfectly for me. However, I would like to implement an HTML form for the API to provide API clients, the form must be able to access the method (to the database model), so that from the same form you can create the users.

I already have the simple form in HTML.

The question is: How do I access the slim models, so that, once the values of the form have been obtained, I will be able to send them to the model to create the user.

My route to create users:

$this->post('crear', function ($req, $res, $args) {
        $r = CandidatoCrearValidation::validate($req->getParsedBody());
        if(!$r->response){
          return $res->withHeader('Content-type', 'application/json')
                    ->withStatus(422)
                    ->write(json_encode($r->setResponse(false,"Campos no validados.")));
        }else{
          return $res->withHeader('Content-type', 'application/json')
                  ->write(
                    json_encode($this->model->candidato->crear($req->getParsedBody()))
                  ); 
        }
      });

My route to show the form:

$this->get('crear/form', function ($req, $res, $args) {
      return $this->renderer->render($res, "form-signin.php", $args);
    });

Ambos están dentro del mismo grupo de la ruta de slim.
image

@stakahashi
Copy link

+1

@odan
Copy link
Contributor

odan commented Feb 2, 2021

the form must be able to access the method (to the database model),

This would break the basic MVC principles, because the "View" layer should not fetch data from somewhere. All the the data should be passed to the View renderer instead.

How do I access the slim models, so that, once the values of the form have been obtained, I will be able to send them to the model to create the user.

You can handle all these operations in the action handler or better in a use case specific (Application) Service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants