本文整理汇总了PHP中Gdn_Model::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Model::insert方法的具体用法?PHP Gdn_Model::insert怎么用?PHP Gdn_Model::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Model
的用法示例。
在下文中一共展示了Gdn_Model::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addPicture
/**
* Add screenshots to an addon.
*
* @param string $AddonID Addon in question.
* @throws Exception No permission manage addon's pictures.
* @throws Gdn_UserException Addon not found.
*/
public function addPicture($AddonID = '')
{
$Session = Gdn::session();
if (!$Session->isValid()) {
$this->Form->addError('You must be authenticated in order to use this form.');
}
$Addon = $this->AddonModel->getID($AddonID);
if (!$Addon) {
throw notFoundException('Addon');
}
if ($Session->UserID != $Addon['InsertUserID']) {
$this->permission('Addons.Addon.Manage');
}
$this->addModule('AddonHelpModule', 'Panel');
$AddonPictureModel = new Gdn_Model('AddonPicture');
$this->Form->setModel($AddonPictureModel);
$this->Form->addHidden('AddonID', $AddonID);
if ($this->Form->authenticatedPostBack() === true) {
$UploadImage = new Gdn_UploadImage();
try {
// Validate the upload
$TmpImage = $UploadImage->validateUpload('Picture');
// Generate the target image name
$TargetImage = $UploadImage->generateTargetName(PATH_UPLOADS, '');
$ImageBaseName = 'addons/screens/' . pathinfo($TargetImage, PATHINFO_BASENAME);
// Save the uploaded image in large size
$ImgParsed = $UploadImage->saveImageAs($TmpImage, changeBaseName($ImageBaseName, 'ao%s'), 700, 1000);
// Save the uploaded image in thumbnail size
$ThumbSize = 150;
$ThumbParsed = $UploadImage->saveImageAs($TmpImage, changeBasename($ImageBaseName, 'at%s'), $ThumbSize, $ThumbSize);
$ImageBaseName = sprintf($ImgParsed['SaveFormat'], $ImageBaseName);
} catch (Exception $ex) {
$this->Form->addError($ex->getMessage());
}
// If there were no errors, insert the picture
if ($this->Form->errorCount() == 0) {
$AddonPictureModel = new Gdn_Model('AddonPicture');
$AddonPictureModel->insert(array('AddonID' => $AddonID, 'File' => $ImageBaseName));
}
// If there were no problems, redirect back to the addon
if ($this->Form->errorCount() == 0) {
$this->RedirectUrl = url('/addon/' . AddonModel::slug($Addon));
}
}
$this->render();
}
示例2: insert
/**
* Automatically add the current core version if not specified in the fields.
*
* @param array $fields The data you want to insert into the model.
* @return bool
*/
public function insert($fields)
{
if (!array_key_exists('CoreVersionID', $fields)) {
$fields['CoreVersionID'] = $this->getCoreVersion()->AddonVersionID;
}
return parent::insert($fields);
}