Com as etiquetas: languages Mostrar/esconder comentários | Atalhos de teclado

  • Lopo Lencastre de Almeida January 13, 2016, às 01:19 Permalink
    Etiquetas: Comparison of web application frameworks, , , Homestead, JSON, languages, Laravel, Object-oriented programming, ORM, PHP, , PHPUnit, ,   

    Laravel 5 Essentials 

    If you have been around for many years you would remember PHP as just a scripting language to be used inside HTML pages. It was really great, if you think that most sites would have to be done using plain C or Perl languages. In the beginning PHP FI was just that.

    But the PHP language became very popular due to its simplicity. It evolved fast throughout the years.

    Since it got better support for modern programming approaches, like OOP, MVC and ORM, it has gained a lot of support from its users and, at first, a lot of small library classes started to pop up and being freely hosted in sites like PHPClasses.org

    Later on, especially since PHP 4, application frameworks started to appear. FLOSS, CodeIgniter and CakePHP were the most famous, along with Zend, but they started to lag behind with the release of PHP 5 due to the need and will to keep backwards compatibility with the old version and all its users.

    This unwillingness, in the pure tradition of free software, originated some forks, like FuelPHP, from developers that wished to move on and use the full strength of PHP 5.

    Some new frameworks, like Symfony, also began to emerge, all with something different in style, functionality or approach.

    Laravel, the subject of this book, took a different approach from all the predecessors to avoid many of the problems and mistakes previous full stack frameworks did.

    The developers decided to make a robust component-based framework on top of the successful and excellent Symfony framework, but also using the “good parts” of other frameworks and libraries, like SwiftMail for email processing.

    If you never worked with a PHP framework then you should start with Laravel and this book is, although short, a great one for it.

    From this book you will learn just the essential on the last version of this framework with simple examples and very easy to understand language suitable for even the novice PHP developer seeking to start developing or migrating his/her apps from another framework or even converting his/her old non-OOP scripts.

    If you are already a seasoned Laravel 4 developer and want to have a reference for the new version then this book was specifically written for you.

    As the author says “this book will give you a tour of Laravel and its core features”, so it will guide you from understanding the Laravel wording and concepts to know, through simple examples, all the basics about Laravel and its tools; like Eloquent ORM, virtual development environment Homestead and its powerful command line tool Artisan.

    First of all, of course, knowledge of PHP and its related technologies are implied, as is some knowledge on OOP. That said lets start touring.

    Chapter 1 gives you an introduction to frameworks and why they can improve your development and your productivity and introduces you to the Model-View-Controller paradigm on which Laravel is based.

    It also introduces you to the concepts and features of Laravel and its new application’s general structure and conventions. At the end you can learn some tips on how to migrate your older Laravel’s applications to the new version.

    Laravel is much more than just a framework and it includes a set of tools to fasten your work so in Chapter 2 you will learn how to setup a development environment using Composer, a dependency manager, to deal with the installation of all the third parties components that Laravel may need and that are not included in its core source.

    You will also learn how to use Homestead, a Vagrant based Virtual Machine box that will allow you to create a full server ready to work with Laravel and without fussing around with your system.

    At the end of the chapter you will learn how to create your first Laravel application inside Homestead and how to perform your daily work with it using Homestead (or you can just use ssh or Putty if you are working on Windows or Mac OS X).

    Now that you already have your environment created and that you have your Laravel also installed in Homestead it’s time to start building your first application.

    That is what you will do in Chapter 3. You will start by planning the URLs and entities that you will use. Learn how to troubleshoot and solve common issues when getting started. After this initial steps you will learn how to define routes and their actions, as well as models and relationships.

    Having done that you may need to have a database for your application so you will learn how to setup your database and how to work with Laravel’s ORM Eloquent. At the end of the chapter you will be presented with Blade, Laravel’s template language to create your interface layouts.

    Chapter 4 is all about Eloquent ORM. You will learn how to use it for every action that concerns databases.

    Although it covers a lot, Eloquent is so feature-rich that the book does not cover all of its features. Neverthless, it covers the most important aspects and you will know how to save and retrieve data, create relations of varying complexity between your data models and also how to handle events raised during your data model’s life cycle.

    In Chapter 5 you will learn the importance of testing your applications and you will see how Laravel 5 was built from the ground up to facilitate it. It comes with everything you will need to get started, including helpers to test your application.

    In this chapter, you will see how Laravel makes it very simple to get started with testing. In this introduction to testing, the author looks at the advantages of writing tests for your application, how to prepare your tests, the software design patterns that Laravel fosters, what is Mockery and how to use it to test objects in isolation, and introduce you to the built-in features and helpers that facilitate testing.

    One of the best things that today’s most used PHP frameworks and applications have is command line tools to fasten your development and automation. Drupal as Drush, WordPress as WP-Cli, Symfony as Pake, just to mention a few.

    In Chapter 6 you will be presented with Laravel’s powerful command line tool, Artisan, and will learn to use it for everything you may need, including rolling your own Artisan commands and how to schedule commands to automate everyday’s web site tasks.

    Chapter 7 is the last one and it’s about securing your application and user authentication. In order to do that you will improve the application you started in chapter 3 by adding a simple authentication system and tackle any security issues we have in the existing code base.

    So you will learn how to configure and use the authentication services, what is the concept of middleware and how to apply it to specific routes, how to validate data and form requests.

    You will also learn what are the most common security vulnerabilities and how Laravel can help you write more secure code.

    At the end of the book there’s an appendix, a non-numbered chapter, with lots of very useful information and code. I will just quote the beginning of it:

    “Laravel comes with several utilities that help you perform specific tasks, such as sending e-mails, queuing functions, and manipulating files. It ships with a ton of handy utilities that it uses internally; the good news is that you can also use them in your applications. This chapter will present the most useful utilities so you do not end up rewriting a function that already exists in the framework!

    The structure of this chapter is partly based on Jesse O’Brien’s cheat sheet, which is accessible at http://cheats.jesse-obrien.ca/ . The examples are based on Laravel’s tests as well as its official documentation and API.”

    Now all the Essential on Laravel is presented to you so you just need to start coding. I hope you enjoy Laravel as much as I do.

    In conclusion

     This book was a bit of an unexpected surprise. For its seven chapters and just 118 pages I was expecting less than I got. Of course, this is just an introductory book so do not expect it to have it all about Laravel 5.


    Neverthless, if you are willing to know more about what modern PHP programming and Laravel is or just want to get a fast update on what’s new in its version 5, then you should read “Laravel 5 Essentials”.

    Laravel is one of the most exciting of the newer PHP frameworks and it will gain market share in the near future. It’s already the most starred PHP framework on Github and that says a lot about its popularity, so you should really consider to have it as one of your expertise areas.

    This book is, for sure, a must have and a very good starting point for all PHP newcomers and old Laravel developers.

    Originaly published at PHPClasses.org

     
  • Lopo Lencastre de Almeida July 27, 2012, às 19:59 Permalink | Responder
    Etiquetas: Cascading Style Sheets, languages, , ,   

    [was:] How to translate/switch specific contents on templates 

    On a discussion at WordPress.org several approaches were proposed to solve the issue mentioned on this post title.

    I think it is not needed such complex stuff and tons of code inside your theme; just turn your theme translatable using _e() and __() functions and creating a POT file (and .po/.mo files for each language) 🙂

    Check Translate a WordPress Theme in 3 Easy Steps for more instructions on how to do it.

    Neverthless, the idea of having a way to change the UI depending on user’s active language is simply great!

    How to change UI design on language change?

    So, I tought about it and proposed that if someone wants to select different CSS files for each active language he/she should just add something like this in his/her theme’s header.php:

    <style type="text/css" media="screen">
    <!-- @import url( <?php bloginfo('template_directory'); ?>/styles/<?php get_bloginfo('language'); ?>.css ); -->
    </style>
    <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/styles/<?php get_bloginfo('language'); ?>.css" type="text/css" media="screen" />

    Of course, you need to have a dir like your_theme/styles and a bunch of CSS files like en-US.css, pt-PT.css and so on.

    On your style.css you just keep the common styles that would work for all languages and on the language specific CSS you keep all the rest, for instance <div> positioning, @webfonts, logo and other imagery replacement, etc.

    You can, of course, use the same trick but put instead your code on your theme’s functions.php like this:

    // Loading mytheme css styles
    function mytheme_styles() {
    // Set the language CSS URI
    $lang_style = get_template_directory_uri().'/styles/'.get_bloginfo('language').'.css";
    // Adding your theme's main CSS style.css
    wp_register_style('mytheme', get_template_directory_uri().'/style.css',,'all');
    // Adding language specific CSS. Add dependency on styles.css
    wp_register_style('mytheme_lang', $lang_style, array('mytheme'));
    // Enqueue both
    wp_enqueue_style('mytheme_lang');
    }
    // Add it to loop
    add_action('wp_head', 'mytheme_styles');

    With this the CSS files will be auto inserted in <head> with the wp_head() function call. And it would benefit of any minifying options you have to speed up your site load.

    Another option you have, if you use an upgradable theme you don’t control totaly (best option is to make a sub-theme but would loose upgrading) is to create a small plugin called, for instance, Custom Language Styling 🙂

    First create an empty file and add the following code in it…

    <?php
    /* Plugin Name: Custom Language Styling
    Description: Set custom styles for specific languages
    Version: 0.1
    License: GPL
    Author: A Great Guy
    Author URI: http://www.example.com/
    */
    function customlangstyling_styles() {
    // Set the language CSS URI
    $lang_style = get_template_directory_uri().'/styles/'.get_bloginfo('language').'.css";
    // Adding your theme's main CSS style.css
    wp_register_style('customlangstyling', get_template_directory_uri().'/style.css',,'all');
    // Adding language specific CSS. Add dependency on styles.css
    wp_register_style('customlangstyling_lang', $lang_style, array('customlangstyling'));
    // Enqueue both
    wp_enqueue_style('customlangstyling_lang');
    }
    // Add it to loop
    add_action('wp_head', 'customlangstyling_styles');

    … then just follow the steps:

    1. save it as customlangstyling.php
    2. create the directory wp-content/plugins/customlangstyling
    3. upload the .php file there
    4. Activate it on your blog dashboard
    5. That’s it 😉

    Hope it helps.

    note:
    You could use pll_current_language('slug') instead of get_bloginfo('language') when using Polylang.
    Check the docs
    and search for pll_current_language to see the syntax and adapt the code as needed.

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Responder
e
Editar
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancelar