我在文章模塊建了了自定義字段{$v[ganxiang]},想在做一個新頁面訪問這個字段和文章內容,標題,怎么在控制器添加選擇新頁面的指定模板,后臺偽靜態怎么寫
總結就是文章內容可以選默認模板的同時也可以選擇另外模板顯示
就是原來顯示/wenzhan/234.html默認模板, /wenzhan/234_new.html 新模板
以下是問AI生成的
public function index($article_id)
{
// 根據文章ID獲取文章內容
$article = model('content')->where('id', $article_id)->find();
// 提取自定義標簽內容
$content = $article['content'];
preg_match_all('/\[ganxiang\](.*?)\[\/ganxiang\]/', $content, $matches);
$custom_tags = $matches[1];
// 將自定義標簽內容傳遞到模板
$this->assign('ganxiang', $custom_tags);
// 渲染模板
return $this->fetch('new/index');
}
}