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

SitePoint PHP Blog:
Building and Processing Forms in Symfony 2
June 06, 2014 @ 13:45:07

The SitePoint PHP blog has a new tutorial posted from author Daniel Sipos about form handling in Symfony2. More specifically, about creating them and handling the results from their submission. This is an introduction to the topic and gets into two examples, one focusing on a view implementation and the other using the form builder.

In this tutorial we will look at two examples of using forms in Symfony 2. In the the first, we will place form elements straight in the View file and then handle the form processing manually in the controller. In the second, we'll use the Symfony form system to declare forms in an object oriented way and have Symfony process and persist the values. We will be working on a simple installation of the Symfony framework.As you may know, it comes with a default bundle called AcmeDemoBundle and we will use that to illustrate working with forms.

In the first example he looks at "non-entity forms" and shows how to create the form from normal HTML elements in the view. The form is just a simple input field and a submit button. He includes the code you'll need to process the form submission too. In the second example he includes an example of how to create the same setup but using the Form Builder instead. It's also links it to a data object, making it simpler to save the submission results.

0 comments voice your opinion now!
symfony2 form processing view builder entity manager tutorial

Link: http://www.sitepoint.com/building-processing-forms-in-symfony-2

U
October 02, 2013 @ 10:56:28

For those that might have heard of traits (made available in newer versions of PHP, 5.4+) but haven't seen much of a practical application, this new post from Matthew Setter could help.

Here's the situation which prompted the use of them, in a nutshell. I had a custom view helper which performed some rather elementary date & time formatting, based purely on US standards. When I first wrote the ViewHelper, I wasn't aware of any other use case I'd have for it. So it made sense for it to be self-contained. Such is life however, as later in development the need did arise to do more date/time formatting. But this time, far removed from the view layer in a model. [...] So I weighed up my options and chose to go with Traits. I'll be honest, there was the new & cool factor to them as well - as well as an irresistible sense of simplicity in them.

He shares the actual trait code he implemented, making two simple methods - one for formatting date and another for formatting the time - for his views to use. He also includes examples of it in use. He also sought some feedback

0 comments voice your opinion now!
zendframework2 traits reuse view helper

Link: http://www.maltblue.com/php/using-traits-for-code-reuse-in-zend-framework-2

Paul Jones:
Aura Has New Releases Input, Sql, and View
September 18, 2013 @ 09:58:54

As Paul Jones mentions in his most recent post (pulled from the Aura blog), the Aura framework has some new releases of its component packages - specifically Input, Sql and View.

On the heels of last week's slew of releases, we have three followups! The Aura.Input package got a feature-level bump to 1.1.0, with a new FormFactory. Thanks to Hari KT for championing that one. Aura.Sql is now at 1.3.0, due to lots of work from MAXakaWIZARD to provide SQLite- and PostgreSQL-specific query objects. Finally, the Aura.View package got a bugfix and is now at 1.2.1; it handles content-type negotiation better for those times when there is no Accept header.

If you'd like more information about the Aura framework, check out the project site or each of the packages that make it up. Aura is a decoupled set of components without additional dependencies.

0 comments voice your opinion now!
aura framework release input sql view component dependency

Link: http://paul-m-jones.com/archives/4731

Rob Allen:
Configuring a ZF2 view helper before rendering
July 31, 2013 @ 09:57:52

Rob Allen has a quick new post with details about configuring a view helper for a Zend Framework 2 application prior to its results being rendered.

When I was reading the documentation for the currencyFormat view helper, I discovered that you could configure the currency code and locale once rather than in every call. [...] This is obviously useful, but even more useful would be if we could set it once by default and then override if we need to in a specific call. The easiest way to do this is to use an event listener on the renderer.post View event within a modules's onBootstrap method.

He includes code to illustrate the process, configuring the renderer in the bootstrap of the application to use the GBP currency code and the "en_GB" locale for formatting its output. You can find out more about what the currencyFormatter can do in Rob's previous post.

0 comments voice your opinion now!
view helper zendframework2 configuration bootstrap

Link: http://akrabat.com/zend-framework-2/configuring-a-zf2-view-helper-before-rendering

Rasmus Larsson:
Building a template engine in PHP
May 31, 2013 @ 11:11:27

Rasmus Larsson has a recent post to his site showing how to build a basic templating engine in PHP that uses the "__toString" to help render the result.

Possibly the most common sign of bad code is tight coupling, especially between logic and presentation. It might seem like a good idea to print out the HTML while the data is being generated, but it more often than not leads to a big incoherent mess of tangled code. [...] While PHP makes it unnecessarily easy to write shitty code it also provides a lot of ways to avoid it. I'll use this post to show you how ridiculously easy it is to create a template engine in PHP in three easy steps.

He includes the sample code for a "Template" class and shows the combination of exporting variables and output buffering to return the resulting template populated with values. The "__toString" method makes it so that you can just echo out the object and get the results.

0 comments voice your opinion now!
template engine tutorial simple tostring view

Link: http://www.rasmuslarsson.se/2013/05/a-template-engine-in-php

PHPMaster.com:
The MVC Pattern and PHP, Part 2
March 12, 2013 @ 11:19:03

PHPMaster.com has posted the second part of their MVC series, introducing you to the Model/View/Controller design pattern. If you want to catch up, part one is here.

Welcome to part 2 of this two-part series discussing MVC and PHP, where we'll discuss some of the considerations one must make when using an MVC architecture. If you've come straight to this article without reading part 1 first, I encourage you to head back and have careful read as this one will assume that you've read and understand everything it discussed.

He talks about some of the things more involved in making a MVC framework including routing and URL formats and working with templates. Sample code is included for the route handling, model/controller relationship and view classes for the templates.

0 comments voice your opinion now!
mvc designpattern introduction tutorial model view controller routing view


PHPMaster.com:
The MVC Pattern and PHP, Part 1
March 05, 2013 @ 13:21:32

If you're new to the world of PHP frameworks, there's one acronym that might confuse you if you don't understand the structure - MVC. In this new tutorial on PHPMaster.com today introduces you to the MVC (Model/View/Controller) design pattern and how it's commonly implemented in PHP.

The Model-View-Control (MVC) pattern, originally formulated in the late 1970s, is a software architecture pattern built on the basis of keeping the presentation of data separate from the methods that interact with the data. In theory, a well-developed MVC system should allow a front-end developer and a back-end developer to work on the same system without interfering, sharing, or editing files either party is working on. [...] In this article, I will go the basic principles of MVC, a run through the definition of the pattern and a quick example of MVC in PHP. This is definitely a read for anyone who has never coding with MVC before or those wanting to brush up on previous MVC development skills.

He starts with an introduction of the overall structure of the pattern, how each part talks with the others. He then talks about each piece in a bit more detail and provides some code examples for some very basic MVC classes. There's no routing or anything connected to them like there would be in a framework - it's just the classes taking the others in as parameters.

0 comments voice your opinion now!
mvc designpattern introduction tutorial model view controller


Andrew Podner:
Lithium Building Views Using Layouts
February 13, 2013 @ 11:54:04

Andrew Podner has written up a new post for his site today about building views/layouts in Lithium and make the maintenance of your application simpler in the long run.

The last time I wrote about the Lithium framework, the focus was on getting information out of a MySQL database. Once you have that information, in many cases you will want to show it to the user. In this installment, we are going to look at how Lithium implements layouts for your output in an effort to improve reusability of code, which ultimately improves the developer's ability to quickly get applications up and running and it makes maintenance down the road that much easier.

He talks about the basic structure of an application (on the file system) and where the layouts and views live inside it. He includes a sample layout that defines areas for things like title, scripts, character set and main content. Code is also included showing how to use it in your application. There's also a bit about setting up a default layout in your "_init" method if you'd like to use it across the entire application.

0 comments voice your opinion now!
lithium view layout tutorial framework


Robert Basic:
Working with custom view helpers in Zend Framework 2
September 12, 2012 @ 09:27:08

In his latest post Robert Basic looks at working with custom view helpers in your Zend Framework 2 application and shows how to implement a simple one to display a simple greeting.

I took the skeleton [Zend Framework 2] application, made it even skinnier by throwing out some (for me) unneeded parts and just put it all besides my old ZF1 code. [...] The first problem I ran into was using custom view helpers, especially view helpers that are more general and don't fit into one specific module. Where to put the code? How to access them in views? The second problem was how to access the service manager from a view helper? And the third problem was how to tell the helper to use a specific value when inside a specific module?

He includes a simple example - the greeting helper - and shows where to place it in the application structure, how to work with the service locator inside it and how to set up some module-specific views inside.

0 comments voice your opinion now!
zendframework2 view helper custom tutorial


PHPMaster.com:
Patterns for Flexible View Handling, Part 2 - Using Decorators
September 05, 2012 @ 11:18:58

PHPMaster.com has posted the second part in their series looking at design patterns in handling views in your framework of choice. In this new article they focus on the decorator pattern, using additional functionality to augment the results from the view being rendered.

It's also feasible to manipulate views in fairly flexible fashion by appealing to the niceties of a few other patterns as well, including the rather underrated Decorators. If you're wondering in what parallel universe Decorators get along with views, in this part I'll be showing how to put them to work side by side in nice orchestration to bring to life yet another view module.

They create a simple example where an HTML element (based on an interface) is rendered - a span tag - with content passed in on creation. They take this same logic and transfer it over to the View handler, making handlers for difference pieces of the content (outer and inner). These decorators are then passed in the data from the view and rendered in order.

0 comments voice your opinion now!
designpattern view handling decorator tutorial



Community Events





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


series install library api code interview application developer release introduction threedevsandamaybe wordpress bugfix community laravel symfony language podcast list configure

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