PHP code example of kapitanluffy / propel-model-parser-bundle

1. Go to this page and download the library: Download kapitanluffy/propel-model-parser-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/ */

    

kapitanluffy / propel-model-parser-bundle example snippets



namespace AppBundle\Controller;

use kapitanluffy\PropelModelParserBundle\PropertyCollection;
use Symfony\Component\HttpFoundation\;

class DefaultController extends Controller
{
    public function indexAction($user_id)
    {
        $user = Model\UserQuery::create()
        ->joinWith('Post')
        ->findOneById($user_id);
        
        $post_count = $user->getPosts()->count();
        
        $properties = new PropertyCollection;
        $properties->addProperty('posts', 'getPosts')
            // parse child object's (post) children (user)
            ->useProperty('posts')
                ->addProperty('poster', 'getUser')
            ->endUse()
            // add custom property
            ->addProperty('post_count', $post_count);
        
        $data = $user->parseObject($properties);
        
        $response = new JsonResponse;
        $response->setData($data);
        return $response;
    }
}