Skip to content

Instantly share code, notes, and snippets.

View cakephp-tutorial's full-sized avatar

CakePHP Italia Tutorial cakephp-tutorial

View GitHub Profile
<?php
#/app/Controller/AuthorsController.php
class AuthorsController extends AppController{
public $scaffold; //attiviamo lo scaffold per poter procedere al CRUD di cakephp
}
<?php
#/app/Controller/BooksController.php
class BooksController extends AppController{
public $scaffold; //attiviamo lo scaffold per poter procedere al CRUD di cakephp
}
<?php
#/app/Model/Author.php
class Author extends AppModel {
public $name = 'Author';
public $displayField = 'name';
//definizione della relazione con altro modello
public $hasMany = array('Book');
}
<?php
#/app/Model/Book.php
class Book extends AppModel {
public $name = 'Book';
public $displayField ='title';
//definizione della relazione con altro modello
public $belongsTo = array('Author');
}
@cakephp-tutorial
cakephp-tutorial / cakphp-routes.php
Last active February 26, 2016 23:15
CakePHP 2 Routes
<?php
//esempio senza pass
Router::connect(
'/controller001/:id',
array('action' => 'view'),
array('id' => '[0-9]+')
);
//esempio con pass
Router::connect(
<?php
//url /blog/3_articolo-di-esempio
Router::connect(
'blog/:id_:slug',
array(
'controller' => 'posts',
'action' => 'view'
),
array(
'pass' => array('id'),
<?php
//url /hobbies/10/roma
Router::connect(
'hobbies/:id/:city',
array(
'controller' => 'hobbies',
'action' => 'search'
),
array(
'pass' => array('id', 'city'),
<?php
Router::connect(
'/:controller/:id',
array('action' => 'view'),
array('id' => '[0-9]+')
);
<?php
Router::connect('/:action', array('controller' => 'home'));
<?php
Router::connect(
'/:controller/:year/:month/:day',
array('action' => 'index'),
array(
'year' => '[12][0-9]{3}',
'month' => '0[1-9]|1[012]',
'day' => '0[1-9]|[12][0-9]|3[01]'
)
);