這裏是我的控制器,它將從某個模型函數獲取URL信息並將其傳遞給我的視圖。如何截斷codeigniter視圖中的字符串
class MyController extends CI_Controller{
public function __construct()
{
parent::__construct();
//load the settings model
//some model
//load the text helper
$this->load->helper('text');
}
public function index()
{
//call the model function to get the Url data
$data['urllist'] = //call the model function and get the array and store it to urllist;
//load the view
$this->load->view("myview",$data);
}
}
和我的看法是
<body>
<?php
/*
//$longurl is an array element and its value is
some thing like
http://example.com/sdsds/sdsdsd/sdsdsdsd/sdsdsd/sdsdsd
i want to truncate it about 20 characters
*/
$lurl=character_limiter($longurl, 20);
echo $lurl;
?>
</body>
,但它顯示完整的URL。我可以在視圖中使用character_limiter嗎?或者我必須截斷它在我的控制器,並通過它來查看?
不要在一個控制器的所有邏輯。 –
什麼意思關於truncate? –