本文整理汇总了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;
}