News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Qandidate.com Blog:
Handling AngularJS POST requests in Symfony
August 14, 2014 @ 11:09:13

The Qandidate.com blog has a quick new post today showing how to handle AngularJS requests with a Symfony framework based backend application. They automate the process of decoding the JSON from the Angular frontend to make it immediately usable to the framework backend.

At Qandidate.com we started using AngularJS last year and I have to say it was love at first sight! Two-way databinding, testability, dependency injection, server communication...awesome! Did I say server communication? We use Symfony 2 (which is awesome too) for our back end API's. Unfortunately AngularJS and Symfony do not speak the same language out-of-the-box. In this post I will show you how we automatically decode JSON requests so we can use it with Symfony's Request object using our symfony-json-request-transformer library (or class actually).

They start with a simple JSON example and the action to handle it (the "postAction") and show the manual json_decode method. Instead of having to do this in each controller action, they define the Request transformer handler. This handler takes the incoming request and allows for modifications to various aspects of the request, including transforming the data. They've posted a full example here that includes the full stack, not just the transformer itself (to show the full flow of the request).

0 comments voice your opinion now!
angularjs request symfony2 transform json request

Link: http://labs.qandidate.com/blog/2014/08/13/handling-angularjs-post-requests-in-symfony/

Jordi Boggiano:
Authentication management in Composer
May 28, 2014 @ 11:07:35

Jordi Boggiano has posted about a new feature in Composer, the popular dependency manager for PHP, around the handling of authentication information.

Up until today if you run a home-grown package repository serving private packages it was quite a pain to use with Composer. You did not have efficient way to password-protect the repository except by inlining the password in the composer.json or by typing the username/password every single time. With the merge of PR#1862 and some further improvements you can now remove credentials from your composer.json!

The new functionality allows for the external storage of the credentials in a file, either globally of in one relative to the repository. He also includes the command you can use to configure and set these username/password combinations and have them stored in the "auth.json" file.

0 comments voice your opinion now!
composer authentication management username password authjson json

Link: http://seld.be/notes/authentication-management-in-composer

PHPBuilder.com:
Processing JSON in PHP
April 04, 2014 @ 10:40:39

PHPBuilder.com has posted a new tutorial today showing you how to work with JSON in PHP including serialization and database interaction.

This article explains how to use the JavaScript Object Notation (JSON) extension in PHP, going step by step through a series of essential operations. JSON is an object string notation, it is defined as a subset of JavaScript's syntax and its general-purpose is to interchange data format. As you probably know, JSON was first made to be used with JavaScript for accessing remote data, but now it is used by many other languages because JSON data is platform independent data format. JSON can be used natively in JavaScript, but you can also use it in a server-client application logic.

They start with an introduction to the JSON structure and how to both create and encode data using PHP's own json_encode and json_decode. The examples start out using arrays for the data but then move into something slightly more complex - objects. The article talks about JsonSerializable and show how to automatically hook the data into a table and store the content based on the column name/property name match.

0 comments voice your opinion now!
process json encode decode tutorial example

Link: http://www.phpbuilder.com/articles/application-architecture/object-oriented/processing-json-in-php.html

SitePoint PHP Blog:
Composer Cheatsheet
April 01, 2014 @ 11:22:35

The SitePoint PHP blog has a new post from Matthew Setter today sharing a Composer cheatsheet he recently discovered with an example of the common commands and "composer.json" file structure.

Unless you've been living under a rock, today's PHP isn't your grandmother's PHP; it's an entirely different, much more elegant and mature language with countless improvements and additions. One of the key additions is Composer, the de facto standard for managing PHP project dependencies which, by default, gives you access to hundreds of ready-made libraries, via Packagist.org.

He goes through the parts of the guide, introducing some of the commands and covering the details of the full "composer.json" JSON structure. There's also a video introduction if you'd like the more visual version.

0 comments voice your opinion now!
composer cheatsheet introduction commands json structure

Link: http://www.sitepoint.com/composer-cheatsheet

HHVM Blog:
Tracking Parity
March 04, 2014 @ 10:43:13

On the HHVM blog today there's a new post shows how far along they are with parity with the PHP language based on the tests from a sampling of several large PHP-based projects.

HHVM has a large suite of unit tests that must pass in several build configurations before a commit reaches master. Unfortunately, this test suite passing doesn't tell you if HHVM can be used for anything useful - so we periodically run the test suites for popular, open source frameworks. [...] The frameworks test page is now public, as is the JSON data backing it (which you're welcome to use).

They look briefly at what exactly is tested (latest stable version, with exceptions) and how it all works. The tests are run once an hour and are based on a completely clean build of HHVM in "csv" mode. The results of the tests are automatically pushed into the MySQL+Memcached system reporting system, accessible via the JSON API.

0 comments voice your opinion now!
parity tracking unittest framework hhvm project json api

Link: http://www.hhvm.com/blog/3611/tracking-parity

Evert Pot:
jCard is now a thing
January 21, 2014 @ 11:04:18

In his most recent post Evert Pot talks about jCard, a JSON-based format that was recently approved to serve up VCard personal information data in an easier-to-parse format.

I'm a big fan of this format. vCards have been around since 1995, and even though we've had a pretty significant update in 2011 in the form of vCard 4.0, the format is still complicated to parse, has a number of problems that go all the way back to the early days. [...] The biggest problem with vCards, is that upon a first glance, the format seems extremely easy to parse and generate with just a couple of string manipulation functions. When you dig deeper into the specifications though, you'll notice that it's actually really complex and hosts a ton of edge cases.

He includes an example of how to generate the jCard format using the Sabre/Object and the resulting output, both in the traditional vCard format and the new jCard structure.

0 comments voice your opinion now!
vcard jcard json format sabre object parse output

Link: http://evertpot.com/jcard-completed

Rob Allen:
Returning JSON errors in a ZF2 application
September 09, 2013 @ 10:49:30

Rob Allen has a quick post to his site for the Zend Framework 2 users out there showing how to return JSON errors from your requests.

If you have a standard ZF2 application and accept application/json requests in addition to application/html, then you have probably noticed that when an error happens, HTML is created, even though the client has requested JSON. One way to fix this is to create a listener on MVC's render event to detect that an error has occurred and substitute a JsonModel in place of the ViewModel. The easiest way to do this in your ApplicationModule.

He includes some example code showing how to attach a listener for rendering ("onRenderError") and the code that defines the renderer itself. It goes through a series of checks on the request and then gets the error information from the Response. Some common errors are caught and replaced with a default message, otherwise its just directly sent to render. He then attaches the whole thing in the bootstrap and shows a simple way to test the output with a cURL call.

0 comments voice your opinion now!
return json zendframework2 application tutorial render

Link: http://akrabat.com/zend-framework-2/returning-json-errors-in-a-zf2-application/

Phil Sturgeon:
CurlFile and the Facebook SDK in PHP 5.5
August 30, 2013 @ 11:19:04

Phil Sturgeon has a new post to his site today looking at a new feature that's included with PHP 5.5, Curlfile, and how he uses it with calls to the Facebook API (and a fix to make it cooperate).

One of the features implemented in PHP 5.5 was CurlFile, a nice addition to the Curl extension to allow you to specify specific arguments as a file for upload. In previous versions (pre-PHP 5.5) the syntax looked like this: [@/foo/bar.jpg]. A little digging around lead me to try this syntax: [new CURLFile('/foo/bar.jpg','image/jpeg')]. Sadly while Curl was happy with this, the Facebook PHP SDK (v3.2.2) was not. It turns out the SDK will turn ANY value you send it in that params array into a string.

To get around the issue, he worked up his own fix to the Facebook PHP SDK and submitted a patch to get it introduced into the tool. He also includes a reminder to filter incoming user data for things containing the "@" too to prevent unwanted file transfers.

0 comments voice your opinion now!
curlfile curl file upload facebook sdk patch json

Link: http://philsturgeon.co.uk/blog/2013/08/curlfile-and-the-facebook-sdk-in-php-55

Community News:
Default JSON Support Licensing Issues in PHP
August 21, 2013 @ 11:13:57

Despite the misleading title, this post on Reddit talks some about a switch that some Linux distributions are making when it comes to JSON support in PHP. They're moving away from the built-in support in favor of including this one.

In a quote from Nikita Popov (a comment on the post) he notes that:

It is true that some Linux distribution switched from json to json-c, but this should be transparent to the user. The standard PHP distribution still ships the JSON extension as it always did. [...] You should all take this chance to switch to PHP 5.5, so you can see that everything works fine and that PHP 5.5 is awesome

He also includes comments from the Remi (Fedora) project about the switch, noting that the end user shouldn't notice any kind of issues. The reasoning behind the switch has to do with licensing and usage issues of the previously built-in extension. You can find out more about that issue in this bug report.

0 comments voice your opinion now!
json extension license pecl jsonc distribution linux

Link: http://www.reddit.com/r/PHP/comments/1ksnzw/php_json_removed_in_php_55

Duckout Blog:
Do Funny Stuff with the Google Charts API and PHP
March 26, 2013 @ 11:40:44

In this recent post to the Duckout blog, they show you how to hook your PHP-based (and database driven) application into the Google Charting API for chart/graph generation.

I think, whenever we see a chart in a magazine, in books or applications our brain say's to us Yeepie!!! Don't read these stupid texts or tables! Just look at the green or yellow line and hope that they are above the other lines or hope that your opinion is the biggest part of the pie¯. This saves us a lot of work and in my opinion we should concentrate on drawing beautiful colorized pie charts, instead of writing long boring articles. But the question is: ¯How do I draw these beautiful colorized pie charts? The simple answer is: you don't have to, because google will draw them for you and you just have to tell them what to draw via the google charts api.

The sample application is a "breakfast rating" tool that logs the results to a MySQL database via PDO calls. The results are then extracted and formated as JSON to be compatible with the Google Charts API data handling. Some sample Javascript is included showing how to call the Charts API with your data and get back a simple line graphing of the data from the database. You can see the application in action here for reference.

0 comments voice your opinion now!
google charts api json tutorial rating database pdo



Community Events





Don't see your event here?
Let us know!


language introduction bugfix library interview package laravel community update install opinion series tips symfony podcast release deployment version framework zendserver

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework