Hi Bob,
I tried to use the custom CRC tutorial.
In a snippet I tried to access a field in my custom table with these lines:
$oUG = $modx->getObject("ugallery_metadata", array());
var_dump($oUG->get("price"));
This works fine. But when I try to get the pagetitle the same way it returns null. I think the missing link between modResource (site_content) and my ugallery package is the reason.
If I update or create a new resource using my custom CRC there is no possibility to access my custom table. If used mostly the code of the custom CRC tutorial.
// filename: ugallerymeta.class.php
require_once MODX_CORE_PATH.'model/modx/modprocessor.class.php';
require_once MODX_CORE_PATH.'model/modx/processors/resource/create.class.php';
require_once MODX_CORE_PATH.'model/modx/processors/resource/update.class.php';
class ugalleryMeta extends modResource {
public $showInContextMenu = true;
function __construct(xPDO & $xpdo) {
parent :: __construct($xpdo);
$this->set('class_key','ugallerymeta');
#echo "<pre>".print_r($this,true)."</pre>";
#die();
}
public static function getControllerPath(xPDO &$modx) {
return $modx->getOption('ugallerymeta.core_path',null,$modx->getOption('core_path').'components/ugallerymeta/').'controllers/';
}
public function getContextMenuText() {
$this->xpdo->lexicon->load('ugallerymeta:default');
return array(
'text_create' => $this->xpdo->lexicon('ugallerymeta'),
'text_create_here' => $this->xpdo->lexicon('ugallerymeta_create_here'),
);
}
public function getResourceTypeName() {
$this->xpdo->lexicon->load('ugallerymeta:default');
return $this->xpdo->lexicon('ugallerymeta');
}
public function getContent(array $options = array()) {
$content = parent::getContent($options);
$year = date('Y');
$content .= '<div class="copyright">© '.$year.'. All Rights Reserved. - KEKS</div>';
$content .= $this->get("price");
return $content;
}
}
class ugalleryMetaCreateProcessor extends modResourceCreateProcessor {
}
class ugalleryMetaUpdateProcessor extends modResourceUpdateProcessor {
/**
* Do any processing before the fields are set
* @return boolean
*/
public function beforeSet() {
$beforeSet = parent::beforeSet();
/**
if ($this->getProperty('shouldBeTrue') == false) {
$this->addFieldError('fieldname','The error message');
}
*/
return $beforeSet;
}
/**
* Do any processing before the save of the Resource but after fields are set.
* @return boolean
*/
public function beforeSave() {
$beforeSave = parent::beforeSave();
if ($this->object->get('longtitle') == 'Send an Error') {
$this->addFieldError('longtitle','Specify a different longtitle!');
}
$this->object->set('content', "Replaced Content"); // works fine
$this->object->set('price', "123"); // no effect
return $beforeSave;
}
/**
* Do any custom after save processing
* @return boolean
*/
public function afterSave() {
$afterSave = parent::afterSave();
$this->modx->log(modX::LOG_LEVEL_DEBUG,'Saving a Copyrighted Page!');
return $afterSave;
}
}
I think the mistake is between the php class, the xml schema and me...
hopefully you have the time and you're in the mood to take a look at the code...
thanks a lot!