PHP code example of satooshi / symfony2contrib-http-foundation-extra-bundle

1. Go to this page and download the library: Download satooshi/symfony2contrib-http-foundation-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/ */

    

satooshi / symfony2contrib-http-foundation-extra-bundle example snippets


# Acme/Bundle/Controller/SiteController.php

use Contrib\Bundle\HttpFoundationExtraBundle\Configuration\File;
use Contrib\Bundle\HttpFoundationExtraBundle\Configuration\Json;

/**
 * @Route("/site")
 */
class SiteController
{
    /**
     * @Route("/csv", name="site_csv")
     * @Method("GET")
     * @File(filename = "test.csv", charset = "Shift_JIS")
     */
    public function csvAction()
    {
        $content = 'item1,item2';

        return array(
            'content' => $content,

            // read file in FileResponse and ignore content if this was set to controller result
            //'path' => './test.csv', 
        );
    }

    /**
     * @Route("/json", name="site_json")
     * @Method("GET")
     * @Json
     */
    public function jsonAction()
    {
    	// result response
    	// {"prop1":"value1","prop2":"value2"}
        return array(
        	'prop1' => 'value1',
        	'prop2' => 'value2'
        );
    }

    /**
     * @Route("/jsonp", name="site_jsonp")
     * @Method("GET")
     * @Json(callbackName = "jsoncallback")
     */
    public function jsonpAction()
    {
    	// request
    	// /site/jsonp?jsoncallback=mycallback
    	// response
    	// mycallback({"prop1":"value1","prop2":"value2"});
        return array(
        	'prop1' => 'value1',
        	'prop2' => 'value2'
        );
    }
}