public function getLife() { $article = Life::getInstance()->orderByRaw('id desc')->get(); if (empty($article)) { return redirect('/'); } $pattern = '#原文:(.*)\\n#i'; foreach ($article as $item) { preg_match($pattern, $item->content, $matches); unset($matches[0]); if (isset($matches[1])) { $item->link = $matches[1]; $item->content = preg_replace($pattern, '', $item->content); } else { } } $this->viewData('navMenuActive', 'life'); $this->viewData('articles', $article); return view('frontend.v2.life', $this->viewData); }
private function saveTimeline($title, $category, $file) { $time = time(); $title = explode('.', $title); $id = $title[0]; $title = isset($title[1]) ? $title[1] : ''; $content = file_get_contents($file); if (empty($id) || !is_numeric($id)) { echo "id not a number"; exit(-1); } $model = Life::find($id); if (!$model) { $model = new Life(); } $model->title = $title; $model->content = $content; if (!$model->save()) { var_dump($model->toArray()); exit(-1); } }