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:
Globally overriding validation messages for ZF2 forms
August 19, 2014 @ 10:46:27

Rob Allen has posted a quick hint about overriding validation messages in a Zend Framework v2 based application. This override is related to the output of a standard form and works globally instead of just on a single form.

One thing that I always do when creating a Zend Framework 2 form is override the validation messages for a number of validators - EmailAddress in particular. I recently decided that I should probably sort this one out once and be done with it. Turns out that it's quite easy assuming that you use the FormElementManger to instantiate your forms.

The post includes all the code you'll need to do the override: a custom validator example, the changes you'll need to make to the configuration and an example of a form that uses the custom handling. He explains each of the parts too, showing how they fit together in your module.

0 comments voice your opinion now!
zendframework2 override validation message form tutorial

Link: http://akrabat.com/zend-framework-2/globally-overriding-validation-messages-for-zf2-forms/

Andrew Podner:
Using Final to Prevent Overrides and Extension
November 26, 2012 @ 10:36:05

In the latest post to his site Andrew Podner takes a quick look at something you don't see too much in PHP applications but is a familiar concept to some coming in to the language from others - using "final" to prevent overrides of the code in your classes.

In a previous post about inheritance, I showed you how to extend a class. One aspect of extending classes that wasn't fully covered was the idea of overriding a method in a class. You can override a method (function) from the base class by simply redefining the method in the child class. [...] There are times though, when you do not want a method to ever be overridden. There may even be cases where you do not want a class to be extended.

His example shows how to use this "final" keyword on a database class, protecting a method (getRecord) that could potentially break the application if changed. This would then give the developer trying to extend the class an error noting that that method cannot be overridden. One thing to note, if you're going to use "final" in your code, be sure you know what you're doing. More often than not, you probably just want something like "private" or "protected" (see this post for a bit more explanation).

0 comments voice your opinion now!
final class method tutorial visibility extend override


PHPWomen.org:
Add values to a symfony form in between save() and serialization to the database
October 05, 2012 @ 08:55:12

Kim Rowan has recently posted this helpful hint to the PHPWomen.org site concerning the addition of values between save/serialization in Symfony (1.4) forms.

OK, I have a Comment model and I want to relate Comment objects to several other different model types. So, I need to be able to persist Comment objects in my database that relate to the author of the comment and one of a handful of other tables, for example, a blog post or a licence record, etc.

She includes the contents of her "schema.yml" definition and the code to create and display a basic form. Inside of her "executeCreate", the form's submission is handled and a "processForm" method is called and the overridden "updateObject " is used to inject the new data (a user ID) into the submission.

0 comments voice your opinion now!
symfony form tutorial override save object inject data


Rob Allen's Blog:
Overriding module configuration in ZF2
February 23, 2012 @ 09:11:01

In a quick new post to his blog, Rob Allen shows how you can override a module's configuration in a Zend Framework 2 application. In his example, he uses the "User" module and overrides two of the "magic paths" it creates.

Let's say that you install the ZF-Common's User module. By default, it sets up its routes under the /user path segment. [...] This config section will create the routes /user and through the magic of child_routes, also create /user/login and other required routes. If you don't want /user and would prefer /member, then it's easy enough to change. Just add a new config file to the project's config/autoload folder.

Code for the configuration files is included with the update to the "ZendMvcRouterRouteStack" to change the ZF-Common User module's setup to point to "/member" instead of "/user" when routed. You can find out more about the module system in ZF2 in the latest version of the manual.

0 comments voice your opinion now!
module zendframework2 configuration override


Drupal4Hu.com:
OOP and PHP or why Drupal rocks and some mistakes
August 24, 2010 @ 11:38:12

On the Drupal4Hu.com site there's a recent post with a complaint about the OOP functionality in PHP and how Drupal developers should deal with its limitations.

While I was always complaining of PHP's inability of adding a method run-time, the problem we face is that you can't replace one either. So if you do what I did in the previous post, namely use the hook-alter patten (already an addition to PHP, I must say) to override the classname, that works. However, if two modules try to do this for two different methods, you fail.

He suggests to those Drupal developers out there that, for version 8 of the popular content management system, they drop the "closed crap that in PHP is called OOP" and work to make something better, implemented themselves. Something that would make it simpler for Drupal developers to create hooks into the main system for their plugins. Be sure to read the comments for other opinions on the post.

0 comments voice your opinion now!
drupal oop mistake opinion runtime method override


SitePoint PHP Blog:
How to Override PHP Configuration Options
March 04, 2010 @ 10:09:45

Craig Buckler has added a new post to the SitePoint PHP blog today that looks at some of the PHP configuration options and how you can change them from two different places (besides the php.ini file).

Configuring PHP is easy. You can change almost any aspect of the interpreter within the php.ini configuration file, e.g. modify error handling, increase memory usage, etc. Unfortunately, problems can occur when you move your application to a live hosting environment or are distributing the code to customers. ISPs usually lock down the php.ini configuration file - especially on shared hosting. This could cause your application to fail.

If you're lucky enough to be able to use htaccess files, his first method will work for you - using the "php_flag" or "php_value" directives to change settings for your entire application. The other option is more on an as needed basis - using the ini_set method to change configuration options. Be careful, though, only some configuration options can be changed using these methods. Some still require changes to the php.ini and a restart of the web server.

0 comments voice your opinion now!
override configuration options phpini tutorial


Alex Netkachov's Blog:
File stream wrapper is overwritable in PHP
April 01, 2009 @ 11:14:47

Alex Netkachov has found out something interesting - the default "file" stream wrapper can be overridden.

I find today that the default "file" stream wrapper in PHP is overwritable. You only need to call stream_wrapper_unregister and then stream_wrapper_register with your wrapper.

He gives an example of a situation where you might need to "catch" certain files as they're requested and replace them with another before they make it back to the source. His example code shows how to create the stream (using stream_open) and set methods to read, write, seek and work directly with the stream resource. It takes the file requested and replaces the "5" in the name - "test.php" is included instead of "test.php5".

0 comments voice your opinion now!
file stream override wrapper include


PHPImpact Blog:
Zend Framework Encapsulating routes into modules
August 04, 2008 @ 13:47:35

On the PHP::Impact blog, Federico Cargnelutti has another helpful tip to use in Zend Framework applications - encapsulating routes into modules.

You can encapsulate routes into modules by splitting the routes into different files and extending the Zend_Controller_Router_Rewrite class. But, what if you want to use the Redirector helper to set a URL based on a registered route?

His method creates the routing instance and overwrites the default getRoute method with a custom one in the extending class.

0 comments voice your opinion now!
zendframework encapsulating route module override custom getroute


Greg Beaver's Blog:
PHP namespaces become much better (Derick take note)
June 23, 2008 @ 11:19:27

Greg Beaver, noting some issues that Derick Rethans had pointed out about namespace support for upcoming PHP versions, has posted about a patch he submitted to solve the problem simply.

The issue Derick pointed out:

In PHP 5.3 this would alias the class Interval in the namespace PEAR::Date to the class Interval. For now, this code would work just fine. However, if PHP would introduce a class "Interval" at some point in the future (and PHP can do this as it owns the global namespace) then the above code would suddenly stop working.

Greg's patch makes it possible to "override" the internal class if need be, making it so that code currently working wouldn't break. All it takes is to "use" is like you normally would and and the magic happens behind the scenes.

0 comments voice your opinion now!
namespace override internal class instance patch php5



Community Events





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


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

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