PHP code example of alks / http-extra-bundle

1. Go to this page and download the library: Download alks/http-extra-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alks / http-extra-bundle example snippets



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Alks\HttpExtraBundle\HttpExtraBundle(),
        // ...
    );
}


use Alks\HttpExtraBundle\Annotation as Http;
class FooController extends \Symfony\Bundle\FrameworkBundle\Controller\Controller
{
    /**
     * This will match the "/user?username=foo" and will automatically call the user repository to find a user with the foo
     * username.
     * 
     * @Route("/user", methods={"GET"})
     * @Http\RequestParam(name="username", bindTo="user", repository="AppBundle\Repository\UserRepository")
     * @return User 
     */
    public function getUserByUsernameAction(User $user)
    {
        return $user;
    }
    
    /**
     * This will match a GET request with optional page and limit query parameters like "/posts?page=3&limit=20"
     * 
     * @Route("/posts", methods={"GET"})
     * @Http\RequestParams({"page","limit"})
     * @Http\Response(context={"groups":{"list"}}, type="json")
     */
    public function getPostsAction($page=1, $limit=10)
    {
        return $this->getDoctrine()->getRepository('AppBundle:Post')->findAllByPage($page,$limit);
    }
}