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

Rob Allen:
Using ZF2 Forms with Twig
September 23, 2014 @ 09:28:53

Rob Allen has a new post today showing how to integrate Zend Framework 2 forms into a Slim framework based application. He started the topic in a previous post and continues, this time using the Twig templating framework to handle the rendering.

The ZF2 view helpers, formRow and formElement now look like Twig functions, however we don't want to have to rewrite all our ZF2 view helpers into Twig. Fortunately, Twig supports the concept of a undefined function callback is called whenever Twig encounters a function that it doesn't know how to call. We can use this to proxy through to the ZendView system and get it to render the ZF2 view helpers.

He shows how to use this callback functionality and a custom view layer with the Slim-Views component to render the output. He includes a simple Slim example, setting up the custom View class as a parser extension and how to register the callback to invoke Twig.

0 comments voice your opinion now!
zendframework twig render slimframework integration tutorial view

Link: http://akrabat.com/zend-framework-2/using-zf2-forms-with-twig/

Stoyan Stefanov:
Server-side React with PHP - part 2
September 19, 2013 @ 09:35:38

In a a previous post Stoyan Stefanov introduced a setup where you could render React templates on the server-side with the help of PHP and the v8 parsing. In this second part of the series, he extends that system and shows how to use it to update views based on new data.

Part 1 ended with todos. The first one was to couple the server-side generated code with the client-side React, so that any updates past the initial page load will be handled by React's client JS, which is where React shines. Let's see how you can do just that.

He gives an example similar to his previous one - displaying a table - but shows how to inject some values from PHP as a JSON string into the component. This time he saves the output of that rendering into a variable and reuses it as a part of a whole site render later.

0 comments voice your opinion now!
react javascript js v8 serverside render tutorial data

Link: http://www.phpied.com/server-side-react-with-php-part-2/

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/

Alessandro Nadalin:
Integrating Twig in Your Legacy PHP Code
June 18, 2013 @ 10:19:49

Alessandro Nadalin has posted a two part series to his site to help you get the Twig templating tool integrated with your legacy codebase.

It might happen that you are working on a legacy code that is years old, with its own templating mechanism1 that doesn't really allow you to take advantage of the benefits that a structured and object-oriented engine like Twig. In this situations, when a complete replacement would cost too much to your organization, you can take advantage of a wild integration between this advanced template engine and your existing code.

In the first part of the series, he proposes integrating it at the base level, essentially wrapping the "render" method of your framework of choice. In the second part of the series, though, he comes back with a "less wild" approach that also lets you take advantage of some of the other features twig has to offer. He modifies the previous example to output a template file and reuse that in the Twig "render" call.

0 comments voice your opinion now!
twig legacy codebase integration template render

Link: http://odino.org/integrating-twig-in-your-legacy-php-code

Bertrand Mansion's Blog:
Twitter Bootstrap and the QuickForm2 Callback Renderer
September 26, 2011 @ 12:23:41

In a new post Bertrand Mansion shows how he combined the versatility of the PEAR QuickForm2 package and the Bootstrap project from Twitter to quickly make a form using the project's styling (CSS).

I don't know about you, but for me building HTML Forms and styling HTML Forms are maybe the most boring things in web development. It's repetitive and takes a lot of time to do things correctly. That's why tools like Twitter's Bootstrap and PEAR's HTML_QuickForm2 can help with this part of our job. Wouldn't it be nice to have QuickForm2 generate a markup compatible with Bootstrap CSS, so that you could get a nice looking form without to much efforts? Well, that's what I plan to do here.

He starts by creating a simple QuickForm2 form with no renderers attached (no pre-defined styles) and a custom render callback that wraps the items in "div" tags with the correct styles. There's also a custom renderer included for grouping items with additional styling attached.

0 comments voice your opinion now!
twitter bootstrap pear quickform2 callback style render css


DevShed:
Violating the Liskov Substitution Principle - PHP
June 30, 2011 @ 08:36:31

On DevShed today there's a new tutorial posted talking about the Liskov Substitution Principle (part of the SOLID set of principles) and how to use it in a practical example using some object-oriented PHP.

However, not all is bad with Inheritance. When used properly it can be a great ally. The question that comes to mind is: how can you keep away from building derivatives that behave totally different from the chosen abstraction(s)? Here's exactly where the Liskov Substitution Principle (LSP) comes into play.

They choose to illustrate the principle in the form of a view renderer that, when an unintentional issue happens, throws a new exception. He creates the abstract class to generate the view objects and creates a few child objects that extend it. using these, he creates a set of templates that render a header/footer/body with the data given. The problem comes up when he tries to work with his objects and a partial view instead of a composite view is passed in.

It's a complicated situation to follow, but it does help make the principle a bit more clear. I'd suggest following it all the way through and possibly even trying out their code (included) to make it even more clear.

0 comments voice your opinion now!
liskov substitution principle tutorial view render exception


Michael Maclean's Blog:
Using Pango for PHP a taster
February 22, 2011 @ 12:58:27

Michael Maclean has a new article today talking about the Pango graphics library and how it can be coupled with the Cairo PECL extension to more easily create better looking text in dynamic images.

The PECL/Cairo library is pretty good at drawing vector graphics (in our opinion, as the developers, at least!), but one thing it's not able to do by itself is draw text with mildly advanced layout. [...] That's because the developers of the Cairo library decided to let another more specialised library handle the job of text layout.

Michael has created a wrapper for Pango in PHP (github) and some sample code that can be used as a test to ensure it's all setup and working. He steps through each part of the image creation and describes what's happening and what each method is doing along the way.

0 comments voice your opinion now!
pango image creation cairo text render tutorial


Till Klampaeckel's Blog:
Zend Framework Slow automatic view rendering
March 30, 2010 @ 14:50:16

In a new entry to his blog, Till Klampaeckel looks at view rendering for Zend Framework applications and how, as he assumed it would, making a change in the automatic rendering on the views could speed things up quite a bit.

My thesis is that there's a gain in page rendering time when I disable automatic view rendering and use explicit render calls ($this->render('foo');) inside my controllers. And to cut to the chase, there is. On our app, I measured a 12% improvement using Xdebug's profiler - simple before-after-style.

He talks a bit about his setup for testing his theory complete with a customized loader as well as the platform (OS and web server) he ran the tests on. He used Xdebug to run the testing. His conclusion is a pretty obvious one - what you gain in convenience you sacrifice in performance.

15 comments voice your opinion now!
zendframework view render automatic


Vinu Thomas' Blog:
pChart - PHP charting library
October 22, 2008 @ 07:53:00

Vinu Thomas points out a nice looking PHP charting library on his blog today - pChart.

Looking for some good looking graphs without having to pay for a library or resort to Flash graphs? Try creating your own using pChart. pChart is a PHP class oriented framework designed to create aliased charts. This project focuses on allowing developers to generate great looking graphs by increasing rendering quality introducing an aliasing algorithm.

It uses GD to create the graphs, so just about any PHP distribution out there will support it (if you're not sure, make a phpinfo() page to check out your setup). There's even some example graphs so you can get an idea of what some of the end results could be.

0 comments voice your opinion now!
pchart chart library gd graphics image render


Christian Weiske's Blog:
PEARhd steaming on
October 16, 2008 @ 08:49:02

Christian Weiske set out on a project - no small thing - to convert the current PEAR documentation info over to the PhD DocBook rendering system. In a new post he talks about the conversion process and some of the technology involved.

The reason for PhD to exist was that the previously used DSSSL based system was slow: a full build (all formats and all languages) took 24 hours to complete. Further, the tools the system based on were old, rusty and nobody understood why they broke on some machines, but also why they worked on other ones. Having a php-based system for PHP ensures that there is always someone around who can fix it if it's broken. This wasn't the case with the old documentation build system.

The conversion was spurred on by the fact that the PEAR documentation stopped building and more and more people were finding it hard to build on their machines too. He walks through the steps he took - installing PhD, converting over the docs to the DocBook 5 format and the first builds with the new system.

Now that at the XML was shiny, too, it was time to actually use PhD on it. The numbers were amazing: While a build for one format and one language took around 40 minutes on my system (dual core Macbook with 2GHz and 2GiB RAM), building the same with PhD takes 45 seconds!
0 comments voice your opinion now!
pear documentation docbook phd render xml xsl



Community Events





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


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

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