本文整理汇总了PHP中xPDO::getManager方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::getManager方法的具体用法?PHP xPDO::getManager怎么用?PHP xPDO::getManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDO
的用法示例。
在下文中一共展示了xPDO::getManager方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
//.........这里部分代码省略.........
$where = '';
foreach ($pkn as $k => $v) {
$vt = PDO::PARAM_INT;
if (in_array($this->_fieldMeta[$k]['phptype'], array('string', 'float'))) {
$vt = PDO::PARAM_STR;
}
if ($iteration) {
$where .= " AND ";
}
$where .= $this->xpdo->escape($k) . " = :{$k}";
$bindings[":{$k}"]['value'] = $this->_fields[$k];
$bindings[":{$k}"]['type'] = $vt;
$iteration++;
}
} else {
$pkn = $this->getPK();
$pkt = PDO::PARAM_INT;
if (in_array($this->_fieldMeta[$pkn]['phptype'], array('string', 'float'))) {
$pkt = PDO::PARAM_STR;
}
$bindings[":{$pkn}"]['value'] = $pk;
$bindings[":{$pkn}"]['type'] = $pkt;
$where = $this->xpdo->escape($pkn) . ' = :' . $pkn;
}
if (!empty($updateSql)) {
$sql = "UPDATE {$this->_table} SET " . implode(',', $updateSql) . " WHERE {$where}";
}
}
}
if (!empty($sql) && ($criteria = new xPDOCriteria($this->xpdo, $sql))) {
if ($criteria->prepare()) {
if (!empty($bindings)) {
$criteria->bind($bindings, true, false);
}
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Executing SQL:\n{$sql}\nwith bindings:\n" . print_r($bindings, true));
}
$tstart = microtime(true);
if (!($result = $criteria->stmt->execute())) {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
$errorInfo = $criteria->stmt->errorInfo();
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $criteria->stmt->errorCode() . " executing statement:\n" . $criteria->toSQL() . "\n" . print_r($errorInfo, true));
if (($errorInfo[1] == '1146' || $errorInfo[1] == '1') && $this->getOption(xPDO::OPT_AUTO_CREATE_TABLES)) {
if ($this->xpdo->getManager() && $this->xpdo->manager->createObjectContainer($this->_class) === true) {
$tstart = microtime(true);
if (!($result = $criteria->stmt->execute())) {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $criteria->stmt->errorCode() . " executing statement:\n{$sql}\n");
} else {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $this->xpdo->errorCode() . " attempting to create object container for class {$this->_class}:\n" . print_r($this->xpdo->errorInfo(), true));
}
}
} else {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
}
} else {
$result = false;
}
if ($result) {
if ($pkn && !$pk) {
if ($pkGenerated) {
$this->_fields[$this->getPK()] = $this->xpdo->lastInsertId();
}
$pk = $this->getPrimaryKey();
}
if ($pk || !$this->getPK()) {
$this->_dirty = array();
$this->_validated = array();
$this->_new = false;
}
$callback = $this->getOption(xPDO::OPT_CALLBACK_ON_SAVE);
if ($callback && is_callable($callback)) {
call_user_func($callback, array('className' => $this->_class, 'criteria' => $criteria, 'object' => $this));
}
if ($this->xpdo->_cacheEnabled && $pk && ($cacheFlag || $cacheFlag === null && $this->_cacheFlag)) {
$cacheKey = $this->xpdo->newQuery($this->_class, $pk, $cacheFlag);
if (is_bool($cacheFlag)) {
$expires = 0;
} else {
$expires = intval($cacheFlag);
}
$this->xpdo->toCache($cacheKey, $this, $expires, array('modified' => true));
}
}
}
}
$this->_saveRelatedObjects();
if ($result) {
$this->_dirty = array();
$this->_validated = array();
}
return $result;
}
示例2: time
// Generate 10 random events in the future
$calendar = $xpdo->getObject('Gregorian', 1);
for ($i = 0; $i < 10; $i++) {
$start = time() + rand(1, 10) * 3600 * 24;
$fields = array('summary' => "Test event number {$i}", 'dtstart' => date('Y-m-d H:i', $start));
if (rand(0, 10) > 5) {
$fields['dtend'] = date('Y-m-d H:i', $start + rand(1, 48) * 3600);
}
$fields['allday'] = rand(0, 10) > 5;
if (rand(0, 10) > 5) {
$fields['description'] = "An event with a description!";
}
if (rand(0, 10) > 5) {
$fields['location'] = "Somewhere, over the rainbow";
}
var_dump($calendar->createEvent($fields));
echo "Event '{$fields['summary']}' on '{$fields['dtstart']}' created<br />\n";
}
break;
case 'createTables':
$xpdo->getManager();
$classes = array('Gregorian', 'GregorianEvent', 'GregorianTag', 'GregorianEventTag');
foreach ($classes as $class) {
$output .= "Trying to create container for class '{$class}'... ";
$result = $xpdo->manager->createObjectContainer($class);
$output .= ($result ? "[Ok]" : "[Failed]") . "<br />\n";
}
break;
}
}
return $output;
示例3: xPDO
exit;
}
}
if ($verbose) {
print_msg(sprintf('<br/><strong>Ok:</strong> The necessary directories exist and have the correct permissions inside of <br/>
<code>%s</code>', $package_dir));
}
// Delete/regenerate map files?
if (file_exists($xml_schema_file) && !$regenerate_schema && $verbose) {
print_msg(sprintf('<br/><strong>Ok:</strong> Using existing XML schema file:<br/><code>%s</code>', $xml_schema_file));
}
$xpdo = new xPDO("mysql:host={$database_server};dbname={$dbase}", $database_user, $database_password, $table_prefix);
// Set the package name and root path of that package
$xpdo->setPackage($package_name, $package_dir, $package_dir);
$xpdo->setDebug($debug);
$manager = $xpdo->getManager();
$generator = $manager->getGenerator();
//Use this to create an XML schema from an existing database
if ($regenerate_schema) {
$xml = $generator->writeSchema($xml_schema_file, $package_name, 'xPDOObject', $table_prefix, $restrict_prefix);
if ($verbose) {
print_msg(sprintf('<br/><strong>Ok:</strong> XML schema file generated: <code>%s</code>', $xml_schema_file));
}
}
// Use this to generate classes and maps from your schema
if ($regenerate_classes) {
print_msg('<br/>Attempting to remove/regenerate class files...');
delete_class_files($class_dir);
delete_class_files($mysql_class_dir);
}
// This is harmless in and of itself: files won't be overwritten if they exist.
示例4: process
public function process()
{
$properties = $this->getProperties();
$prefix = isset($properties['prefix']) && !empty($properties['prefix']) ? $properties['prefix'] : null;
$restrictPrefix = true;
if (isset($properties['usecustomprefix']) && !empty($properties['usecustomprefix'])) {
$prefix = isset($properties['prefix']) ? $properties['prefix'] : null;
if (empty($prefix)) {
$restrictPrefix = false;
}
}
$packageName = $properties['packageName'];
//$tablename = $properties['tablename'];
$tableList = isset($properties['tableList']) && !empty($properties['tableList']) ? $properties['tableList'] : null;
//$tableList = array(array('table1'=>'classname1'),array('table2'=>'className2'));
$packagepath = $this->modx->getOption('core_path') . 'components/' . $packageName . '/';
$modelpath = $packagepath . 'model/';
$schemapath = $modelpath . 'schema/';
$schemafile = $schemapath . $packageName . '.mysql.schema.xml';
if (file_exists($packagepath . 'config/config.inc.php')) {
include $packagepath . 'config/config.inc.php';
if (is_null($prefix) && isset($table_prefix)) {
$prefix = $table_prefix;
}
$charset = '';
if (!empty($database_connection_charset)) {
$charset = ';charset=' . $database_connection_charset;
}
$dsn = $database_type . ':host=' . $database_server . ';dbname=' . $dbase . $charset;
$xpdo = new xPDO($dsn, $database_user, $database_password);
//echo $o=($xpdo->connect()) ? 'Connected' : 'Not Connected';
} else {
$xpdo =& $this->modx;
}
$manager = $xpdo->getManager();
$generator = $manager->getGenerator();
if ($properties['task'] == 'createPackage' || $properties['task'] == 'writeSchema') {
// create folders
if (!is_dir($packagepath)) {
mkdir($packagepath, 0777);
}
if (!is_dir($modelpath)) {
mkdir($modelpath, 0777);
}
if (!is_dir($schemapath)) {
mkdir($schemapath, 0777);
}
}
if ($properties['task'] == 'createPackage') {
if (!file_exists($schemafile)) {
$handle = fopen($schemafile, "w");
}
}
if ($properties['task'] == 'writeSchema') {
//Use this to create a schema from an existing database
$xml = $generator->writeSchema($schemafile, $packageName, 'xPDOObject', $prefix, $restrictPrefix, $tableList);
}
if ($properties['task'] == 'parseSchema') {
//Use this to generate classes and maps from your schema
// NOTE: by default, only maps are overwritten; delete class files if you want to regenerate classes
$generator->parseSchema($schemafile, $modelpath);
}
if ($properties['task'] == 'alterfields' || $properties['task'] == 'addmissing' || $properties['task'] == 'removedeleted' || $properties['task'] == 'checkindexes') {
$prefix = empty($prefix) ? null : $prefix;
$options['addmissing'] = 0;
$options['removedeleted'] = 0;
$options[$properties['task']] = 1;
$this->modx->addPackage($packageName, $modelpath, $prefix);
$pkgman = $this->modx->migx->loadPackageManager();
$pkgman->parseSchema($schemafile, $modelpath, true);
$pkgman->checkClassesFields($options);
}
if ($properties['task'] == 'loadSchema') {
if (file_exists($schemafile)) {
return $this->success('', array('content' => @file_get_contents($schemafile)));
//$this->setPlaceholder('schema', @file_get_contents($schemafile));
}
}
if ($properties['task'] == 'createTables') {
//$prefix = empty($prefix) ? null : $prefix;
$this->modx->addPackage($packageName, $modelpath, $prefix);
$pkgman = $this->modx->migx->loadPackageManager();
$pkgman->parseSchema($schemafile, $modelpath, true);
$pkgman->createTables();
}
if ($properties['task'] == 'saveSchema') {
$fp = @fopen($schemafile, 'w+');
if ($fp) {
$result = @fwrite($fp, stripslashes($properties['schema']));
@fclose($fp);
}
}
return $this->success();
}