型號製作自定義網址笨
function get_footer_pages(){
$query=$this->db->where('section','footer');
$query=$this->db->get('pages');
if($query->num_rows()>0){
$result=$query->result_array();
return $result;
}else{
return false;
}
}
function get_url($row){
$title=$row['title'];
$not_allowed=array('/','?','\"','&','"',':','%','\'',',');
$title=str_replace($not_allowed,'',$title);
$title=str_replace(' ','-',$title);
$title=$title."_".$row['id'];
return $title;
}
控制器:
$data['footer_pages']=$this->Home_model->get_footer_pages();
查看:
<?php foreach($footer_pages as $f_pages){ ?>
<li><a href="<?php echo $f_pages['url'] ?>"><?php echo $f_pages['name'] ?></a></li>
<?php } ?>
我想創建一個正如我在功能get_url()
執行組合和id
。
現在的問題:
是我怎麼能叫這個get_url()
在get_footer_pages()
做出的get_footer_pages()
所有結果的URL和href
使用的網址,我VIEW
?
你的手段我必須在助手文件夾中創建一個文件任何名稱,然後'get_url()'保存在幫助文件中。並在我看來調用該函數? –
是的。你需要在你的'application/config/autoload.php'文件中將這個幫助文件添加到helpers autoload數組中。 – trajchevska
如果我在我的視圖中執行get_url()的所有功能,那麼? –