本文整理汇总了PHP中app\models\News::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP News::insert方法的具体用法?PHP News::insert怎么用?PHP News::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAdd
public function actionAdd()
{
if (!isset($_POST['NewsHeader']) || !isset($_POST['NewsPreview']) || !isset($_POST['NewsText']) || !isset($_POST['NewsTags'])) {
header("HTTP/1.0 404 Not Found");
throw new E404Exception('Required params can not be null');
}
$NewsRecord = new News();
$NewsRecord->NewsHeader = $_POST['NewsHeader'];
$NewsRecord->NewsPreview = $_POST['NewsPreview'];
$NewsRecord->NewsText = $_POST['NewsText'];
$NewsRecord->NewsTags = $_POST['NewsTags'];
$NewsRecord->publishdate = 'NOW()';
$NewsRecord->insert();
$mail = new \PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Username = 'shilov.kirill.transas@gmail.com';
$mail->Password = 'qwertyASDFGHzxcvbn';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = '465';
$mail->addAddress('shilov.kirill.transas@gmail.com');
$mail->Body = 'Created news';
$mail->AltBody = 'Body created';
$mail->send();
$mail->clearAddresses();
header('Location: ./index.php');
}
示例2: actionInsert
public function actionInsert()
{
$view = new View();
$view->display('insert.php');
$article = new News();
$article->title = $_POST['title'];
$article->text = $_POST['text'];
$article->insert();
}
示例3: actionAddNews
public function actionAddNews()
{
$article = new ModelNews();
$title = $_POST['title'];
$text = $_POST['text'];
$article->title = $title;
$article->text = $text;
$article->insert();
$send = new SendMail();
if ($send->send()) {
header("Location: http://" . $_SERVER['SERVER_NAME'] . "/");
} else {
throw new \Exception("Ошибка при отправлении письма о добавлении новости!");
}
}