Console für Fortgeschrittene

Die Console ist ein mächtiges Tool – am Anfang reicht ein cake bake und alles wird gut.
Später will man mehr und man bekommt mehr.

In dem Projekt https://github.com/MontBlanc-Sucks/CakePHP2.0StudyApp ist eine Definitionsdatei für die Datenbankstruktur vorhanden.

 
// file \app\Config\Schema\schema.php 
 
/* App schema generated on: 2011-06-22 10:16:19 : 1308705379*/
class AppSchema extends CakeSchema {
	function before($event = array()) {
		return true;
	}
 
	function after($event = array()) {
	}
 
	var $posts = array(
		'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'collate' => NULL, 'comment' => ''),
		'title' => array('type' => 'string', 'null' => false, 'default' => NULL, 'collate' => 'utf8_general_ci', 'comment' => '', 'charset' => 'utf8'),
		'body' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'comment' => '', 'charset' => 'utf8'),
		'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
		'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB')
	);
	var $users = array(
		'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary', 'collate' => NULL, 'comment' => ''),
		'username' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'comment' => '', 'charset' => 'utf8'),
		'password' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'comment' => '', 'charset' => 'utf8'),
		'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
		'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB')
	);
}

Und wie bekommt man nun die Tabellen angelegt?
Einfach cake Schema create eingeben und schon geht’s los.

 

Und danach stehen die Tabellen zur Verfügung und das Ganze unabhängig von der eingesetzten Datenbank – wenn man spezifische Informationen wie ‚engine‘ => ‚InnoDB‘ weglässt.

Mehr dazu Console and Shells

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert