我使用CodeIgniter中的模板分析器類爲視圖(MVC)設計師友好的外觀。我有一系列我想要顯示的帖子,但是在首頁上,我只想要顯示帖子的一部分(前200個字符),然後是「更多」鏈接。操作CodeIgniter分析文本
它正在輸出帖子,但似乎忽略PHP substr()函數bc文本全長出來。
裏面的模型類:
function __construct()
{
parent::__construct();
$this->load->library('parser');
$this->load->model('MPosts');
}
function index() // BASE_URL
{
$data = array("article_posts" => $this->MPosts->get_posts());
$this->parser->parse('VPosts', $data);
}
的視圖中:
<body>
{article_posts}
<h2><a href="posts/post/{postID}">{title}</a></h2>
<p><?=substr("{post}", 0, 200);?>...</p>
<p><a href="posts/post/{postID}">Read More</a></p>
<hr />
{/article_posts}
</body>
您需要爲您的模型獲取'index()'中文章的'substr()'。然後,只需執行'
{post} ...
' –您是否指控制器的index()?謝謝。我希望避免這種情況,但看起來我可能不得不這樣做。 – Glyph
你能否改變你的句子「文字全長」,因爲輸出實際上是「{post}」? –