本文整理汇总了PHP中Gdn_Model::Insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Model::Insert方法的具体用法?PHP Gdn_Model::Insert怎么用?PHP Gdn_Model::Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Model
的用法示例。
在下文中一共展示了Gdn_Model::Insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Picture
public function Picture($UserReference = '')
{
$this->Permission('Garden.SignIn.Allow');
$Session = Gdn::Session();
if (!$Session->IsValid()) {
$this->Form->AddError('You must be authenticated in order to use this form.');
}
$this->GetUserInfo($UserReference);
$this->Form->SetModel($this->UserModel);
$this->Form->AddHidden('UserID', $this->User->UserID);
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_ROOT . DS . 'uploads');
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images
@unlink(PATH_ROOT . DS . 'uploads' . DS . 'p' . $this->User->Photo);
// Don't delete this one because it hangs around in activity streams:
// @unlink(PATH_ROOT . DS . 'uploads' . DS . 't' . $this->User->Photo);
@unlink(PATH_ROOT . DS . 'uploads' . DS . 'n' . $this->User->Photo);
// Save the uploaded image in profile size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
// Save the uploaded image in preview size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
// Save the uploaded image in thumbnail size
$ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
} catch (Exception $ex) {
$this->Form->AddError($ex->getMessage());
}
// If there were no errors, associate the image with the user
if ($this->Form->ErrorCount() == 0) {
$PhotoModel = new Gdn_Model('Photo');
$PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName));
if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) {
$this->Form->SetValidationResults($this->UserModel->ValidationResults());
}
}
// If there were no problems, redirect back to the user account
if ($this->Form->ErrorCount() == 0) {
Redirect('garden/profile/' . $UserReference);
}
}
$this->Render();
}
示例2: Picture
public function Picture($UserReference = '', $Username = '')
{
$this->Permission('Garden.SignIn.Allow');
$Session = Gdn::Session();
if (!$Session->IsValid()) {
$this->Form->AddError('You must be authenticated in order to use this form.');
}
$ImageManipOk = FALSE;
if (function_exists('gd_info')) {
$GdInfo = gd_info();
$GdVersion = preg_replace('/[a-z ()]+/i', '', $GdInfo['GD Version']);
if ($GdVersion < 2) {
throw new Exception(sprintf(T("This installation of GD is too old (v%s). Vanilla requires at least version 2 or compatible."), $GdVersion));
}
} else {
throw new Exception(sprintf(T("Unable to detect PHP GD installed on this system. Vanilla requires GD version 2 or better.")));
}
$this->GetUserInfo($UserReference, $Username);
$this->Form->SetModel($this->UserModel);
$this->Form->AddHidden('UserID', $this->User->UserID);
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_ROOT . DS . 'uploads');
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images
@unlink(PATH_ROOT . DS . 'uploads' . DS . 'p' . $this->User->Photo);
// Don't delete this one because it hangs around in activity streams:
// @unlink(PATH_ROOT . DS . 'uploads' . DS . 't' . $this->User->Photo);
@unlink(PATH_ROOT . DS . 'uploads' . DS . 'n' . $this->User->Photo);
// Save the uploaded image in profile size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
// Save the uploaded image in preview size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
// Save the uploaded image in thumbnail size
$ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
} catch (Exception $ex) {
$this->Form->AddError($ex->getMessage());
}
// If there were no errors, associate the image with the user
if ($this->Form->ErrorCount() == 0) {
$PhotoModel = new Gdn_Model('Photo');
$PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName));
if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) {
$this->Form->SetValidationResults($this->UserModel->ValidationResults());
}
}
// If there were no problems, redirect back to the user account
if ($this->Form->ErrorCount() == 0) {
Redirect('dashboard/profile/' . $UserReference);
}
}
$this->Render();
}