Frameworks da nova Era PHP FuelPHP

Preview:

Citation preview

FRAMEWORKS DA NOVA ERA PHP

DAN JESUS

SOBRE MIM

$danjesus = [ “developer” => [“php”, js”, “ruby”, “java”, “objective-c”], “where” => [“LQDI Digital”, “Co-founder Solhys Tecnologia”], “blog” => [“danjesus.github.io”] ]; !return $danjesus;

FUELPHP

FuelPHP is a simple, flexible, community driven

PHP 5.3+ framework, based on the best ideas of

other frameworks, with a fresh start!

FUELPHP

MODULAR

BOOTSTRAP SIMPLES

EXTENSÍVEL

H-MVC

INSTALAÇÃO

curl get.fuelphp.com/oil | shvia curl

git clone git://github.com/fuel/fuel.gitvia git

OIL COMMAND LINE

oil create cell console generate package refine help server test

oil create {app name}criando o app usando oil

Instala as dependências com composer

Clona o repositório git

Executa os submódulos

criando um controller

oil generate controller {actions}oil generate controller Posts index view add

criando um model

oil generatemodeloil generate controller Post index view add

scaffolding criando automaticamente

oil generate scaffoldoil generate scaffold Post title:varchar[200] content:text

migrations

oil generatemigration {name}oil generate migration add_image_to_post image:varchar[200]

ESTRUTURA FUEL

Composer

Documentação

Sua appFuel Core

Assets css/js/img

Pacotes do Fuel Auth | Orm *

ESTRUTURA APPArquivo de inicialização da appCache

ControllersModelsModel ViewConfiguraçõesI18n internacionalizaçãoArquivos de logMigrationsMódulosTarefasTestesArquivos temporáriosLibs de terceirosViews html, mustache, twig

CONTROLLER

CONTROLLER BASE

REST HYBRID

TEMPLATE

class Controller_Posts extends Controller {}

class Controller_Posts extends Controller_Template {}

class Controller_Posts extends Controller_Rest {}

class Controller_Posts extends Controller_Hybrid {}

BASE

TEMPLATE

REST

HYBRID

ESTRUTURA CONTROLLER

class Controller_Posts extends Controller { ! public function action_index() { return Response::forge(View::forge('posts/index')); } !}

ESTRUTURA CONTROLLER

class Controller_Posts extends Controller { ! public function action_index() { return Response::forge(View::forge('posts/index')); } !}

Prefixo Controller_ pode ser alterado nas configurações para usar um namespace

ESTRUTURA CONTROLLER

class Controller_Posts extends Controller { ! public function action_index() { return Response::forge(View::forge('posts/index')); } !}

Tipo do controller

ESTRUTURA CONTROLLER

class Controller_Posts extends Controller { ! public function action_index() { return Response::forge(View::forge('posts/index')); } !}

action poder um verbo http como get, post, put, delete

CONTROLLER TEMPLATE

class Controller_Posts extends Controller_Template { //default template.php $this->template = 'template-name'; ! public function action_index() { $this->template->title = 'Template Controller'; $this->template->content = View::forge('posts/index'); } }

CONTROLLER TEMPLATE

class Controller_Posts extends Controller_Template { //default template.php $this->template = 'template-name'; ! public function action_index() { $this->template->title = 'Template Controller'; $this->template->content = View::forge('posts/index'); } }

Permite a passagem de variáveis e views para o template.

CONTROLLER TEMPLATE

class Controller_Posts extends Controller_Template { //default template.php $this->template = 'template-name'; ! public function action_index() { $this->template->title = 'Template Controller'; $this->template->content = View::forge('posts/index'); } } View que será renderizada dentro desta

área no template

CONTROLLER TEMPLATE

class Controller_Posts extends Controller_Template { //default template.php $this->template = 'template-name'; ! public function action_index() { $this->template->title = 'Template Controller'; $this->template->content = View::forge('posts/index'); } } View que será renderizada dentro desta

área no template

CONTROLLER REST

class Controller_Test extends Controller_Rest { protected $format = 'json'; ! public function get_list() { return $this->response(array( 'foo' => Input::get('foo'), 'baz' => array( 1, 50, 219 ), 'empty' => null )); } }

CONTROLLER REST

class Controller_Test extends Controller_Rest { protected $format = 'json'; ! public function get_list() { return $this->response(array( 'foo' => Input::get('foo'), 'baz' => array( 1, 50, 219 ), 'empty' => null )); } }

Formato pode ser json, xml, csv, html, php ou serialize

CONTROLLER REST

class Controller_Test extends Controller_Rest { protected $format = 'json'; ! public function get_list() { return $this->response(array( 'foo' => Input::get('foo'), 'baz' => array( 1, 50, 219 ), 'empty' => null )); } }

action pode ser get, post, put, delete ou patch

CONTROLLER HYBRIDclass Controller_Post extends Controller_Hybrid { protected $format = 'json'; ! public function action_index() { $this->template->content = View::forge('posts/index'); } ! public function get_list() { return $this->response(array( 'foo' => Input::get('foo'), 'baz' => array( 1, 50, 219 ), 'empty' => null )); } }

MODEL

namespace Model; !class Welcome extends \Model { ! public static function get_results() { // Interações com o banco de dados } !}

ORMMODEL CRUD

DB QUERY

namespace Model; !class User extends \Model_Crud { protected static $_properties = array( 'id', 'name', 'age', 'birth_date', 'gender', ); ! protected static $_table_name = 'users'; }

MODEL CRUD

User::find_all(); !User::find(); !User::forge(array( 'name' => 'teste', 'age' => 'teste' ... ));

MODEL CRUD

namespace Model; !use Orm\Model; !class User extends Model { protected static $_properties = array( 'id', 'name', ); ! protected static $_table_name = 'users'; ! protected $_observers; protected $_belongs_to; protected $_has_many; protected $_has_one; protected $_many_many; }

ORM

ORM

$user = new User(); $user->name = 'Dan Jesus'; $user->save(); !$users = User::find('all');

VIEW

MUSTACHETWIGJADEHAML

SMARTY

PARSER

'always_load' => array( 'packages' => array( 'parser', ), )

arquivo config.php

Habilitando package parser

$view = View::forge('path/to/view', array( 'menu' => $menu, 'articles' => $articles, 'footer_links' => $footer_links, ))->auto_filter(); !return $view;

PARTIALS

echo render('path/to/view', array( 'menu' => $menu, 'articles' => $articles, 'footer_links' => $footer_links, ));

CONFIGURAÇÕES

DEVELOPMENTPRODUCTION

STAGINGTEST

'profiling' => true

arquivo config.php

Habilitar php quick profiller

arquivo config.php

'controller_prefix' => 'Controller\\' Usar namespace nos controllers

arquivo developement/db.php

return array( 'default' => array( 'connection' => array( 'dsn' => 'mysql:host=localhost;dbname=fuel_dev', 'username' => 'root', 'password' => 'root', ), ! 'profilling' => true ), );

Configuração do banco de dados

arquivo config.php

Habilitando Packages'always_load' => array( 'packages' => array( 'orm', ), )

arquivo routes.php

return array( '_root_' => 'welcome/index', // The default route '_404_' => 'welcome/404', // The main 404 route 'hello(/:name)?' => array('welcome/hello', 'name' => 'hello'), );

public static function validate($factory) { $val = Validation::forge($factory); $val->add_field('title', 'Title', 'required|max_length[50]'); $val->add_field('content', 'Content', 'required'); ! return $val; }

Validações no model

FUEL CORE

Projeto no Github https://github.com/fuelphp

Contribuindo com FuelPHP https://github.com/fuel/fuel/wiki/Contributing

FuelPHP issue tracker http://fuelphp.com/contribute/issue-tracker

FuelPHP 2.0 http://fuelphp.com/blogs/2013/08/2-0-an-update

REFERÊNCIAS

PERGUNTAS?

OBRIGADO!

Recommended