Return object base on request uri

Paul Chu

so I have this modular web application that has doctrine2 intergrated with zend framework 1.12.

So I want to return one object base on the request uri, for example: url/api/people/1, which return the person one base on their id.

*side note, I can return all objects of people, I just want to select one object once the user enter's a number.

What I have tried, was to grab the parameter from the url and just pass it through the find function, but doctrine doesn't understand these numbers passed through the uri, and believes they're actions.

  if($this->getRequest()->isGet())
  {
    $request = $this->getRequest();
    $id = $request->getParam('peopleId');

    $em = $this->getEntityManager();
    $peopleRepo = $em->getRepository('API\Entity\People');
    $people = $peopleRepo->find(3); //$id goes into find function

      $resultArray[] = 
      [
        'id'         => $people->getId(),
        'firstname'  => $people->getFirstName(),
        'lastname'   => $people->getLastName(),
        "food"       => $people->getFavoriteFood()
      ];
    echo json_encode($resultArray, JSON_PRETTY_PRINT);
    var_dump($people);

*****EDIT***** So I have added code that I can manually find one person, but I want to do that through the url, how can I achieve this?

Hokusai

Try:

$peopleRepo = $em->getRepository('API\Entity\People')->findBy(array('id' => $id));

Or

$peopleRepo = $em->getRepository('API\Entity\People')->findById($id);

See Doctrine docs: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-objects.html#by-simple-conditions

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Return content based on REQUEST_URI by PHP

Return derived object pointer in base class object

Putting all request data in a URI vs in an object (REST)

Axios - get request URI data from the response object

Parse request.object.existed() return false

How to return a user object from a request

return the object on GET request Exception filters

Angular Http Get request return Array(2)[Object, Object] but undefined

How the get the modified URI of a Request object after modifying the query through the "query" object?

Routing by $_SERVER["REQUEST_URI"] only works for base url and returns 404 Not Found on pages

how to get the base url from jsp request object?

SWAGGER 2 Inheritance for Request and Response Objects from same Base Object

How to make a network request and return a json object in Dart

How to return JSON object when Bad Request MVC

GET request to front end server and return JSON object

Using a promise to return a request object from an HTTP interceptor

React - Return object from helper method get request

how to make a GET request to return the information in a nested object, Mongoose Express

TypeScript cannot return object with same base as generic parameter

R: Suppress base graphics plot but return plot as object

How to only return specific object list base on the condition

How to find and return an object of <derived type> in a list of <base type>?

Return base64 of a File object using FileReader.readAsDataURL()

Laravel request URI not working

How to read the request URI?

Rewrite request URI in dart

Jena relative URI base

Is it ever possible for the getPath method of a java.net.URI object to return null? (If so, when?)

NGINX $request_uri vs $uri

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive