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

Pineco.de:
Appending API and Web Routes to Eloquent Models
Aug 22, 2018 @ 17:54:06

The Pineco.de blog has a tutorial posted showing Laravel users how to append API and web routes to Eloquent models directly without the need for setting up additional route handling.

As a level zero, we can agree on using the RESTful URI scheme. That means every model has an associated route. We can perform different actions on the model, depending on the request type.

It can be a bit painful to concatenate the strings and IDs all the time, so we could append this URL as an attribute of the model. That means we could calculate the URL behind the scenes, and use it on the PHP or the JS side as well. [...] Then only difference (in this simple example) between the API and the web routes is that the API routes have a /api prefix in the URL.

The tutorial then introduces their custom Routable trait that can be included in any model to handle requests on both the API and web side (differentiated by the "api" prefix). The last step is to append the routes to the model itself using the appends Eloquent property.

tagged: laravel tutorial append api web route model eloquent

Link: https://pineco.de/appending-api-and-web-routes-to-eloquent-models/

SitePoint PHP Blog:
High-Performance String Concatenation in PHP
Oct 05, 2010 @ 17:08:08

On the SitePoint PHP Blog there's a new post today looking at performance in string concatenation where they compare some of the different methods for appending values and which might give you that minute edge.

This could be a more important to your application: large string operations are often handled on the server when generating HTML pages. There are no special libraries in the standard PHP installation and string concatenation is implemented using the dot operator. [...] You can also join an array of strings using the implode function.

In order to simulate a larger set of string concatenations, they create a loop of 30,000 and append a simple string - "String concatenation." - each time. One method uses the standard period append method and the other uses implode after appending to an array. The result of their testing is that the array/implode method takes twice as long as the standard period/append operator. Take into account, however, that for most applications, the performance difference will be so small, it wouldn't be noticed.

tagged: performance append string concatenation optimize

Link:

Matthew Weier O'Phinney's Blog:
From the inside-out: How to layer decorators
Apr 07, 2009 @ 14:35:53

Matthew Weier O'Phinney has posted the second part of his look at decorators in Zend Framework applications. This time he shows the process behind using multiple decorators to alter the same content pushed through each, one after the other.

You may have noticed in the previous installment that the decorator's render() method takes a single argument, $content. This is expected to be a string. render() will then take this string and decide to either replace it, append to it, or prepend it. This allows you to have a chain of decorators -- which allows you to create decorators that render only a subset of the element's metadata, and then layer these decorators to build the full markup for the element.

He gives the example of a custom form element (as was created in the previous part) and how to split it out into two different parts - one object for the main input element and the other to alter the object and add a label. He mentions overcoming a few issues like appending content instead of overwriting, controlling the order they run in and marking where to add the new content to the content of the object.

tagged: form decorator tutorial zendframework append content designpattern

Link:

Matthew Turland's Blog:
Zend_Form and Zend_Loader_PluginLoader SNAFU
Apr 03, 2009 @ 13:47:36

Matthew Turland has ammended a previous technique he suggested about using a centralized set of plugin loaders for Zend_Form elements (part of the Zend Framework) because of an issue it can cause with the Zend_Loader_Plugin.

The bug entails Zend_Loader_PluginLoader allowing multiple instances of the same path to be added per prefix. This becomes an issue because of how Zend_Form handles adding subforms. [...] If both the form and subform are using the same plugin loaders, the bug causes the same paths to be added multiple times.

As of the posting of this article, the issue has not been corrected. The solution is outlined in the description of the bug if you want to correct the problem yourself until the full patch is included.

tagged: zendform zendloaderpluginloader snafu bug append path fix

Link:

Havard Eide's Blog:
Iterators
Aug 06, 2008 @ 17:52:35

Havard Eide looks at another aspect of the Standard PHP Library in a new blog post today - iterators.

[It's] a set of classes in the SPL that implements various iterating patterns: ArrayIterator, AppendIterator, FilterIterator, LimitIterator and NoRewindIterator. Hopefully you'll get a idea of what these are capable of and that you can get some new ideas for your day-to-day tasks.

He breaks it down into example of each, explaining what they can be used for, how they work and a code example of each in action (with output). You can find more information in iterators and their functions in the SPL section of the manual.

tagged: iterator tutorial array append filter limit norewind

Link:

Stoyan Stefanov's Blog:
JS/PHP string concatenation mistype
Oct 31, 2007 @ 17:04:00

"Cross-over" developers out there (those that use PHP and Javascript on a regular basis) can sometimes get confused by little syntax things. Stoyan Stefanov got tripped up by just such an issue.

The front-end developer is a strange beast who has to jiggle to and fro and code in several languages literally at the same time - javascript, html, css, php or some other server side language, some SQL dialect... No wonder that sometimes we make silly mistakes.

His issue was with appending - in Javascript, it's a plus but in PHP, it's a period. Unfortunately, the problem can be hard to track down since Javascript also has a use for the period operator - treating the preceding thing like an object.

tagged: concatenation syntax javascript append concatenation syntax javascript append

Link:

Stoyan Stefanov's Blog:
JS/PHP string concatenation mistype
Oct 31, 2007 @ 17:04:00

"Cross-over" developers out there (those that use PHP and Javascript on a regular basis) can sometimes get confused by little syntax things. Stoyan Stefanov got tripped up by just such an issue.

The front-end developer is a strange beast who has to jiggle to and fro and code in several languages literally at the same time - javascript, html, css, php or some other server side language, some SQL dialect... No wonder that sometimes we make silly mistakes.

His issue was with appending - in Javascript, it's a plus but in PHP, it's a period. Unfortunately, the problem can be hard to track down since Javascript also has a use for the period operator - treating the preceding thing like an object.

tagged: concatenation syntax javascript append concatenation syntax javascript append

Link:

Ibzi's Blog:
Start caching all your pages in 5 steps
Feb 19, 2007 @ 16:12:00

On ibzi's blog today, there's a quick guide to introducing caching to your PHP application via a simple PHP file to create the cached pages.

Caching your pages can be pretty useful, especially if you have PHP-generated pages that uses a lot of MySQL queries. Once your pages are cached, your server won’t waste speed and RAM on regenerating the pages, it will just load it from the cache. I’m going to show you how to get PHP to cache your pages, and you can probably do this within 5 minutes.

You'll need to be able to add (and use) an .htaccess file for Apache to use this method, but once it's set up, the simple script works like a charm. It prepends the caching functionality to each page and checks to see if a copy already exists. If it does, it displays it and if not, it will display it and create the cached file.

tagged: cache application simple tutorial apache htaccess prepend append cache application simple tutorial apache htaccess prepend append

Link:

Ibzi's Blog:
Start caching all your pages in 5 steps
Feb 19, 2007 @ 16:12:00

On ibzi's blog today, there's a quick guide to introducing caching to your PHP application via a simple PHP file to create the cached pages.

Caching your pages can be pretty useful, especially if you have PHP-generated pages that uses a lot of MySQL queries. Once your pages are cached, your server won’t waste speed and RAM on regenerating the pages, it will just load it from the cache. I’m going to show you how to get PHP to cache your pages, and you can probably do this within 5 minutes.

You'll need to be able to add (and use) an .htaccess file for Apache to use this method, but once it's set up, the simple script works like a charm. It prepends the caching functionality to each page and checks to see if a copy already exists. If it does, it displays it and if not, it will display it and create the cached file.

tagged: cache application simple tutorial apache htaccess prepend append cache application simple tutorial apache htaccess prepend append

Link:

Jacob Santos' Blog:
My Love For Array Object Idiocy
Aug 04, 2006 @ 11:24:51

In his latest blog entry, Jacob Santos looks at objects and his seeming faciation with every little thing they do - specifically the Array objects.

I suppose I'm fixated on objects, but damn it, they are awesome. Recently, I've been thinking of creating a framework that takes array and file functions and creates a class wrapper around them. It would have been nice if PHP offered an object for handling Arrays and Files. SPL does manage some sorting for arrays, but I would like to fully manage arrays through the internal Array methods.

He dives deeper into the Array objects, looking at how to use them, appending them to each other, how much overhead making the object causes (testing), and the results of those tests.

tagged: array object spl append use testing userland results array object spl append use testing userland results

Link:


Trending Topics: