本文整理汇总了PHP中ArticleModel::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP ArticleModel::insert方法的具体用法?PHP ArticleModel::insert怎么用?PHP ArticleModel::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArticleModel
的用法示例。
在下文中一共展示了ArticleModel::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addAction
public function addAction()
{
$p = $_REQUEST;
$tCateMO = new CategoryModel();
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$pTitle = empty($p['title']) ? Tool_Fnc::ajaxMsg('文章标题不能为空') : Tool_Fnc::safe_string($p['title']);
$pCateid = empty($p['cate_id']) ? 0 : intval($p['cate_id']);
$pContent = empty($p['content']) ? Tool_Fnc::ajaxMsg('内容不能为空') : Tool_Fnc::safe_string($p['content']);
$pHeadimg = empty($p['head_img']) ? '' : Tool_Fnc::safe_string($p['head_img']);
$pDescription = empty($p['description']) ? '' : Tool_Fnc::safe_string($p['description']);
$pSource = empty($p['source']) ? '' : Tool_Fnc::safe_string($p['source']);
$pInitview = empty($p['initview']) ? '0' : intval($p['initview']);
$pStatus = empty($p['status']) ? '0' : intval($p['status']);
$pPushtime = empty($p['push_time']) ? Tool_Fnc::ajaxMsg('请选择日期') : Tool_Fnc::safe_string($p['push_time']);
$pPushtime = time($pPushtime);
$tTime = time();
$tCateRow = $tCateMO->field('*')->where('id = ' . $pCateid)->fRow();
if (empty($tCateRow['id'])) {
Tool_Fnc::ajaxMsg('请选择文章分类');
}
$tHeadimg = '';
if (!empty($_FILES['img'])) {
$tImgurl = '/articleimg/' . date('Y') . '/' . date('m') . '/';
$tDir = APPLICATION_PATH . '/public' . $tImgurl;
$tUpload = new Tool_Upload($_FILES['img'], $tDir);
$tSavename = $tUpload->getSaveName();
$tExt = $tUpload->extension;
$tFile = $tSavename . '.' . $tExt;
$tRes = $tUpload->upload($tSavename);
if ($tRes == 1) {
$tHeadimg = Yaf_Registry::get("config")->web->url->staticimg . $tImgurl . $tFile;
}
}
$tAMO = new ArticleModel();
$tData = array('head_img' => $tHeadimg, 'title' => $pTitle, 'content' => $pContent, 'description' => $pDescription, 'created' => $tTime, 'cate_id' => $pCateid, 'cate_name' => $tCateRow['name'], 'cate_title' => $tCateRow['title'], 'source' => $pSource, 'initview' => $pInitview, 'status' => $pStatus, 'push_time' => $pPushtime);
if (!$tAMO->insert($tData)) {
Tool_Fnc::ajaxMsg('添加失败');
}
Tool_Fnc::ajaxMsg('添加成功', 1);
}
$tDatas = $tCateMO->field('id,pid,name,title')->fList();
$this->assign('tCatelist', Tool_Fnc::getSortedCategory($tDatas));
}