Contenu connexe Similaire à Php 07 Cakephp (20) Plus de Regis Magalhães (20) Php 07 Cakephp15. Bake Welcome to CakePHP v1.2.0.6311 beta Console -------------------------------------------------------------- App : app Path: C:ampplitetdocsocadorapp -------------------------------------------------------------- Interactive Bake Shell -------------------------------------------------------------- [D]atabase Configuration [M]odel [V]iew [C]ontroller [P]roject [Q]uit What would you like to Bake? (D/M/V/C/P/Q) 20. Base de Dados usando MySQL <?php class DATABASE_CONFIG { var $default = array ( 'driver' => 'mysql' , 'persistent' => true , 'host' => 'localhost' , 'port' => '' , 'login' => 'root' , 'password' => '' , 'database' => 'prog_web' , 'schema' => '' , 'prefix' => '' , 'encoding' => 'utf8' ); // ... } ?> app/config/database.php 21. Base de Dados usando MySQLi <?php class DATABASE_CONFIG { var $default = array ( 'driver' => 'mysqli' , 'persistent' => true , 'host' => 'localhost' , 'port' => '0' , 'login' => 'root' , 'password' => '' , 'database' => 'prog_web' , 'schema' => '' , 'prefix' => '' , 'encoding' => 'utf8' ); // ... } ?> app/config/database.php 22. Olá, Mundo!!! <?php class HelloController extends AppController { var $uses = array (); var $autoRender = false ; function index() { echo 'Olá, Mundo!!!' ; } } ?> app/controllers/hello_controller.php 23. Olá, Mundo!!! <?php class HelloController extends AppController { var $uses = array (); function index() { } } ?> < p > Olá, Mundo!!! </ p > app/views/hello/index.ctp app/controllers/hello_controller.php 24. Envio de dados do controlador para a visão <?php class HelloController extends AppController { var $uses = array (); function index() { $this ->set( 'nome' , 'Regis' ); } } ?> < p > Olá, <?php echo $nome ; ?> . </ p > app/views/hello/index.ctp app/controllers/hello_controller.php 34. Validação <?php class User extends AppModel { var $name = 'User' ; var $validate = array ( 'login' => 'alphaNumeric' , 'email' => 'email' , 'born' => 'date' ); } ?> 35. Validação <?php class Genero extends AppModel { var $name = 'Genero' ; var $useTable = 'generos' ; var $displayField = 'descricao' ; var $validate = array ( 'descricao' => VALID_NOT_EMPTY); //... } ?> 36. Validação <?php class Filme extends AppModel { var $name = 'Filme' ; var $useTable = 'filmes' ; var $validate = array ( 'titulo' => array ( array ( 'rule' => array ( 'minLength' , 1 ), 'message' => 'Não pode ficar em branco' ), array ( 'rule' => array ( 'maxLength' , 50 ), 'message' => 'Texto muito longo.' )), 'sinopse' => array ( 'rule' => array ( 'minLength' , 1 )), 'ano_lancamento' => array ( 'numeric' ) ); //... } ?> 37. Validação <?php class User extends AppModel { var $name = 'User' ; var $validate = array ( 'login' => array ( 'alphanumeric' => array ( 'rule' => 'alphaNumeric' , 'required' => true , 'message' => 'Alphabets and numbers only' ), 'between' => array ( 'rule' => array ( 'between' , 5 , 15 ) ) ), 'password' => array ( 'rule' => array ( 'minLength' , '8' ), 'message' => 'Mimimum 8 characters long' ), 'born' => array ( 'rule' => 'date' , 'message' => 'Enter a valid date' , 'allowEmpty' => true ) ); } ?> 40. Associações <?php class User extends AppModel { var $name = 'User' ; var $hasOne = 'Profile' ; var $hasMany = array ( 'Recipe' => array ( 'className' => 'Recipe' , 'conditions' => 'Recipe.approved = 1' , 'order' => 'Recipe.created DESC' )); } ?> 41. Associações <?php class Filme extends AppModel { var $name = 'Filme' ; var $useTable = 'filmes' ; // ... var $belongsTo = array ( 'Genero' => array ( 'className' => 'Genero' , 'foreignKey' => 'genero_id' , 'conditions' => '' , 'fields' => '' , 'order' => '' ) ); } ?> 50. Controller <?php class PessoasController extends AppController { var $scaffold ; } ?> app/controllers/pessoas_controller.php 54. $html->link <?php echo $html ->link( 'Filmes' , array ( 'controller' => 'filmes', 'action' => 'index' )); ?> <?php echo $html ->link( 'Gêneros' , array ( 'controller' => 'generos', 'action' => 'index' )); ?> 65. AROs $aro = new Aro(); $aro ->create( $user_id , $parent_id , $alias ); $aro ->create( 0 , null, 'Presidents' ); $aro ->create( 0 , null, 'Artists' ); $aro ->create( 1 , null , 'Bob Marley' ); $aro ->create( 2 , null , 'Jimi Hendrix' ); $aro ->create( 3 , null , 'George Washington' ); $aro ->create( 4 , null , 'Abraham Lincoln' ); $aro ->setParent( 'Presidents' , 'George Washington' ); $aro ->setParent( 'Presidents' , 'Abraham Lincoln' ); $aro ->setParent( 'Artists' , 'Jimi Hendrix' ); $aro ->setParent( 'Artists' , 'Bob Marley' ); ?> 66. ACOs $aco = new Aco(); $aco ->create( $id , $parent , $alias ); $aco ->create( 1 , null, 'Electric Guitar' ); $aco ->create( 2 , null, 'United States Army' ); $aco ->create( 3 , null, 'Fans' ); 67. ACL <?php class SomethingsController extends AppController { var $components = array ( 'Acl' ); function someAction() { // ALLLOW $this ->Acl->allow( 'Jimi Hendrix' , 'Electric Guitar' ); $this ->Acl->allow( 'Bob Marley' , 'Electric Guitar' ); $this ->Acl->Allow( 'Presidents' , 'United States Army' ); $this ->Acl->allow( 'George Washington' , 'Electric Guitar' , 'read' ); $this ->Acl->allow( 'Abraham Lincoln' , 'Electric Guitar' , 'read' ); // DENY $this ->Acl->deny( 'Abraham Lincoln' , 'United States Army' ); } } ?> 68. ACL <?php class AppController extends Controller{ var $components = array ( 'Acl' ); function checkAccess( $aco ){ $access = $this ->Acl->check( $this ->Session-> read( 'user_alias' ), $aco , $action = "*" ); if ( $access === false ) { echo "access denied" ; exit ; } else { echo "access allowed" ; exit ; } } } ?> $this ->Acl->check( $aro , $aco , $action = '*' );