本文整理匯總了PHP中CakeSchema::after方法的典型用法代碼示例。如果您正苦於以下問題:PHP CakeSchema::after方法的具體用法?PHP CakeSchema::after怎麽用?PHP CakeSchema::after使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CakeSchema
的用法示例。
在下文中一共展示了CakeSchema::after方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _run
/**
* Runs sql from _create() or _update()
*
* @param array $contents
* @param string $event
* @param CakeSchema $Schema
* @return void
*/
protected function _run($contents, $event, &$Schema)
{
if (empty($contents)) {
$this->err(__d('cake_console', 'Sql could not be run'));
return;
}
Configure::write('debug', 2);
$db = ConnectionManager::getDataSource($this->Schema->connection);
foreach ($contents as $table => $sql) {
if (empty($sql)) {
$this->out(__d('cake_console', '%s is up to date.', $table));
} else {
if ($this->_dry === true) {
$this->out(__d('cake_console', 'Dry run for %s :', $table));
$this->out($sql);
} else {
if (!$Schema->before(array($event => $table))) {
return false;
}
$error = null;
try {
$db->execute($sql);
} catch (PDOException $e) {
$error = $table . ': ' . $e->getMessage();
}
$Schema->after(array($event => $table, 'errors' => $error));
if (!empty($error)) {
$this->err($error);
} else {
$this->out(__d('cake_console', '%s updated.', $table));
}
}
}
}
}
示例2: _runSchema
/**
* Runs sql from _createSchema()
*
* NOTE: adapted from the schema shell lib/Cake/Console/Command/SchemaShell.php
*
* @param array $contents
* @param string $event
* @param CakeSchema $Schema
* @return string
*/
protected function _runSchema($db, $contents, $event, &$Schema)
{
$out = '';
if (empty($contents)) {
$this->error('Sql could not be run');
return false;
}
foreach ($contents as $table => $sql) {
if (empty($sql)) {
$out .= sprintf("%s is up to date.\n", $table);
} else {
if (!$Schema->before(array($event => $table))) {
return false;
}
$error = null;
try {
$db->execute($sql);
} catch (PDOException $e) {
$error = $table . ': ' . $e->getMessage();
}
$Schema->after(array($event => $table, 'errors' => $error));
if (!empty($error)) {
$this->error($error);
return false;
} else {
$out .= sprintf("%s updated\n", $table);
}
}
}
return $out;
}