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.

Web api accept object parameter?

Hi everyone,

I've worked with ASP.NET before and in ASP.NET Web API, I could do something like this

public Product Add(Product item)
    {
        if (item == null)
        {
            throw new ArgumentNullException("item");
        }
        item.Id = _nextId++;
        products.Add(item);
        return item;
    }

I mean I can create a model class (Product) and put an instance of it in parameter

How can I do this in Phalcon Micro? Recently, with Micro, I can only put primitive type as parameter.

Thank you very much



6.1k
Accepted
answer

Hi you cant retieve PHP object from HTTP.

But you can create additional layer for that.

for example


call SomeController
{
    $private repository;

    public function __construct(SomeRepository $repo)
    {
        $this->repository = repository;
    }

    public function addAction($id = "")
    {
        $product = $this->repository->findByID($product);
        $this->repository->add($product)
    }
}