Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Archive for Październik, 2013

Developer Drive: Introducing Laravel, part 2

Developer Drive: Introducing Laravel, part 2

The Developer Drive blog has posted the second part of their series introducing the Laravel PHP framework. In this new tutorial they build on the basics from part one to briefly discuss controllers and the Eloquent ORM.

In the first part of this introductory mini series we looked at simple routes and views and now we’ll look at how to work with controllers and models , how these two fit in the framework and how to use them.

They explain some of the basics of controllers first including a bit of sample code showing how to output a basic view and add a new route. Following that is a brief look at using the ORM and making a model – a Post – and defining the table it relates to.

Link: http://www.developerdrive.com/2013/10/introducing-laravel-part-2/
Source: http://www.phpdeveloper.org/news/20310

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

7PHP.com: Auto Generate Properties Dynamically For Your Classes Using Magic Methods & Reflection

7PHP.com: Auto Generate Properties Dynamically For Your Classes Using Magic Methods & Reflection

Accessing private class properties via getters and setters is a pretty standard way to write your applications. Unfortunately it can be time consuming to write them for every property your class may have. On 7PHP.com Khayrattee Wasseem has a few ideas (including using PHP’s own Reflection functionality) to dynamically create them.

When coding a project, at times (or most of it?) some classes might have more than 3 fields (for whatever reason it suits you). So instead of each time writing and repeating setters and getters (accessor methods), I would like to have a piece of reusable code for all my classes without me ever writing a single line of code for accessors. (‘ever’ as in ‘very very rarely’). Now, we also have to take into consideration that some fields might be only get-able or only set-able – (our re-usable piece of code should cater for this)

He shows two different methods to accomplish this kind of dynamic access, one using traits and the other using normal class inheritance. HE includes the code illustration each solution and talks a bit at the end of each section of why that method might be better than the other.

Link: http://7php.com/magic-dynamic-properties/
Source: http://www.phpdeveloper.org/news/20309

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Chris Hartjes: Data Providers and Arrays

Chris Hartjes: Data Providers and Arrays

Chris Hartjes, testing guru, has a post talking about using arrays in data providers for your unit tests. More specifically about some odd behavior one developer was seeing in their tests.

I was asked a question on Twitter by Tex Morgan about a problem he was having with PHPUnit data providers. He was trying to pass in some data and kept wondering why PHPUnit was serializing the data instead of doing what he was expecting.

The issue (example code included) was in how the data providers are expecting the data to be returned. His test was expecting an array but the data provider was returning things incorrectly. As Chris points out, the provider should return an array of arrays. The fix is easy, but could be confusing to someone not used to this slightly unusual return format.

Link: http://www.littlehart.net/atthekeyboard/2013/10/26/data-providers-and-arrays/
Source: http://www.phpdeveloper.org/news/20308

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Hasin Hayder: Install and Run Symfony 2.3.6 projects in OpenShift instances in just one minute

Hasin Hayder: Install and Run Symfony 2.3.6 projects in OpenShift instances in just one minute

Hasin Hayder has a new post today sharing a boilerplate configuration and setup he’s created to get Symfony2 running on OpenShift in “just one minute”. OpenShift is RedHat’s platform as a service that makes it easier to set up and deploy web apps.

Okay, I have written an article 2 days ago where I went through every details. But today. I have created a blank symfony container with all the necessary deploy hook and mods so that you can get your symfony 2 project up and running in an openshift container within a minute, fully automated, seriously!

This repository helps you set up the Symfony instance that’s ready to go. He walks you through the steps you’ll need to create the OpenShift “gear” and configure it to work with Symfony and MySQL.

Link: http://hasin.me/2013/10/27/install-and-run-symfony-2-3-0-in-openshift-instances-in-just-one-minute-with-this-boilerplate-repository/
Source: http://www.phpdeveloper.org/news/20307

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Permutation algorithm

Permutation algorithm

You might remember me writing several articles explaining different sorting algorithms. I might come back to that series as there are few sorting algorithms I haven’t gone through.

But I wanted to do something else now, this is an interesting algorithm to find all permutations of a string.

Let’s say you have string “bar”. The steps are as follows:

  1. If the string is just a one letter, return it.
  2. Remove the first letter of the string and find all permutations of the new string. Do this recursively.
  3. For each found permutation, insert the remove letter from the previous step at every single position. Add each of these strings as a result.
  4. Return the array of results.

Here is implementation in JavaScript:

function permutations(word) {
    if (word.length <= 1) {
        return [word];
    }

    var perms = permutations(word.slice(1, word.length)),
    char = word[0],
    result = [],
    i;
    perms.forEach(function (perm) {
        for (i = 0; i < perm.length + 1; i += 1) {
            result.push(perm.slice(0, i) + char + perm.slice(i, perm.length));
        }
    });

    return result;
}

Source: http://blog.richardknop.com/2013/10/permutation-algorithm/

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

SitePoint PHP Blog: Selling Downloads with Stripe and Laravel

SitePoint PHP Blog: Selling Downloads with Stripe and Laravel

On the SitePoint PHP blog there’s a new tutorial posted showing you how to integrate Laravel and Stripe to make a simple system for selling downloads of software. Stripe is a developer friendly, easy to use payment system that helps you take and manage payments.

Digital goods are an increasingly valuable commodity. [...] In this article I’ll show how you can implement a simple store selling digital goods using PHP along with Stripe, a payment provider who aims to make it easier than ever to take online payments since you don’t need to set up special merchant accounts or deal with complex payment gateways.

He points you to the Stripe site to set up an account before getting started. With that in hand, They start in on the Laravel setup and project creation. He helps you make a “downloads” table to handle path to the file and price. Also included are the model for the Downloads and a “seeder” with some fixture data to work with. From there he shows how to make a simple home page and a “buy” page with a form for the payment information. The Stripe javascript library is then integrated and the response is handled. If it’s a success, the user is then forwarded to another endpoint to download the file they paid for.

Link: http://www.sitepoint.com/selling-downloads-stripe-laravel/
Source: http://www.phpdeveloper.org/news/20296

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

SitePoint PHP Blog: Selling Downloads with Stripe and Laravel

SitePoint PHP Blog: Selling Downloads with Stripe and Laravel

On the SitePoint PHP blog there’s a new tutorial posted showing you how to integrate Laravel and Stripe to make a simple system for selling downloads of software. Stripe is a developer friendly, easy to use payment system that helps you take and manage payments.

Digital goods are an increasingly valuable commodity. [...] In this article I’ll show how you can implement a simple store selling digital goods using PHP along with Stripe, a payment provider who aims to make it easier than ever to take online payments since you don’t need to set up special merchant accounts or deal with complex payment gateways.

He points you to the Stripe site to set up an account before getting started. With that in hand, They start in on the Laravel setup and project creation. He helps you make a “downloads” table to handle path to the file and price. Also included are the model for the Downloads and a “seeder” with some fixture data to work with. From there he shows how to make a simple home page and a “buy” page with a form for the payment information. The Stripe javascript library is then integrated and the response is handled. If it’s a success, the user is then forwarded to another endpoint to download the file they paid for.

Link: http://www.sitepoint.com/selling-downloads-stripe-laravel/
Source: http://www.phpdeveloper.org/news/20296

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

NetTuts.com: Dates and Time – The OOP Way

NetTuts.com: Dates and Time – The OOP Way

On NetTuts.com today there’s a new tutorial they’ve posted showing how to use PHP’s DateTime functionality in a more OOP kind of way. The DateTime extension lets you work both ways – procedural and OOP, with only slightly different syntax changes between them.

The Date/Time PHP extension is a set of classes that allow you to work with almost all of the date and time related tasks. It’s been available since the release of PHP 5.2 and the extension introduced several new classes.

The tutorial first shows you some of the differences between just working with something like date and DateTime. From there they get into a bit more complicated things like:

  • Modifying dates/times
  • Working with multiple dates
  • Working with timezones
  • Using DatePeriods
  • Extending the current functionality

There’s also two more “real world” usage scenarios included – defaulting to using UTC times and using the DateInterval to handle subscription payment logic.

Link: http://net.tutsplus.com/tutorials/php/dates-and-time-the-oop-way/
Source: http://www.phpdeveloper.org/news/20295

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

NetTuts.com: Dates and Time – The OOP Way

NetTuts.com: Dates and Time – The OOP Way

On NetTuts.com today there’s a new tutorial they’ve posted showing how to use PHP’s DateTime functionality in a more OOP kind of way. The DateTime extension lets you work both ways – procedural and OOP, with only slightly different syntax changes between them.

The Date/Time PHP extension is a set of classes that allow you to work with almost all of the date and time related tasks. It’s been available since the release of PHP 5.2 and the extension introduced several new classes.

The tutorial first shows you some of the differences between just working with something like date and DateTime. From there they get into a bit more complicated things like:

  • Modifying dates/times
  • Working with multiple dates
  • Working with timezones
  • Using DatePeriods
  • Extending the current functionality

There’s also two more “real world” usage scenarios included – defaulting to using UTC times and using the DateInterval to handle subscription payment logic.

Link: http://net.tutsplus.com/tutorials/php/dates-and-time-the-oop-way/
Source: http://www.phpdeveloper.org/news/20295

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Google Cloud Platform Blog: Google App Engine for PHP with PhpStorm

Google Cloud Platform Blog: Google App Engine for PHP with PhpStorm

On the Google Cloud Platform blog there’s a recent post showing you how to directly integrate the Google App Engine PHP support with the popular PHP IDE PhpStorm for seamless development.

Our IDE for PHP, PhpStorm, provides seamless integration with Google App Engine for PHP – allowing you to locally develop, debug and deploy your PHP applications on Google App Engine. When testing your application locally, we also support full emulation of App Engine services through the App Engine Development server. The [introductory] video shows how to get started with Google App Engine for PHP in PhpStorm. We also have a comprehensive tutorial which covers Google App Engine with PhpStorm in detail.

His example shows how to integrate the IDE with the Google Cloud SQL service. He shows how to create a new user (via the API console) and how to connect that user in PhpStorm. He includes a CREATE statement for a sample table and the PHP code to connect.

Link: http://googlecloudplatform.blogspot.cz/2013/10/google-app-engine-for-php-with-phpstorm.html
Source: http://www.phpdeveloper.org/news/20294

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>