重定向Url错误

时间:2015-04-06 20:08:22

标签: php redirect

好吧,几天前我发现任务有些问题。我需要做的是:确保网址格式正确,如果不是,请重定向到正确的网址。在其他网址中,我没有遇到任何问题,但是我有这个问题。无论如何,我会尽力以最好的方式解释错误。我在我的模型中有这个功能列出了学习内容:

public function get_learning_category_list() {
$categorias = $this->db->select('t1.id, t1.title, t1.metadata, t1.meta_title, t1.description, t1.meta_description, t1.meta_spam, t1.url, t1.alt_img')
        ->from('learning_category t1')
        ->join('learning_rel_category t4', 't1.id = t4.category_id', 'left')
        ->join('learning t2', 't4.learning_id = t2.id', 'left')
        ->join('learning_rel_language t3', 't2.id = t3.learning_id', 'left')
        ->where('t3.language', $this->language)
        ->group_by('t1.id')
        ->get()->result_array();
    foreach($categorias as $c){
        $total = $this->db->select('count(learning_rel_language.learning_id) as total', false)
        ->from('learning')
        ->join('learning_rel_language', 'learning.id = learning_rel_language.learning_id', 'inner')
        ->join('learning_rel_category', 'learning.id = learning_rel_category.learning_id', 'inner')
        ->where('learning_rel_category.category_id', $c['id'])
        ->where('learning_rel_language.language', $this->language)
        ->group_by('learning_rel_language.language')->get()->first_row('array');

        $metadata = json_decode($c['metadata']);
        $tt = $c['title'];
        $url = $c['url'];
        if($this->language != 'pt_br'){
            $tt = $metadata->{$this->language};
            $tt_pt_br = $c['title'];
        }

        $return[] = array('url' => $url, 'title'=>$tt, 'id'=>$c['id'], 'total'=>$total['total'], 'title_pt_br'=>$tt_pt_br);

    }

她会给我一个数组:

Array ( [0] => Array ( [url] => [title] => Courses on how to generate qualified leads [id] => 2 [total] => 6 [title_pt_br] => ) [1] => Array ( [url] => [title] => Social Media Marketing Courses [id] => 3 [total] => 2 [title_pt_br] => )...

模型具有定义url的格式的函数:

 public function url_format_category($category, $lang_domin) { 
    if (lang('abbr') == 'en_US')
        $lang_domin = 'en/';
    else if (lang('abbr') == 'es_US')
        $lang_domin = 'es/';

    $categorias = $this->learn->get_learning_category_list();
    foreach($categorias as $cat){
        $cat = (object) $cat;
        if($cat->title != '') {
            $return = strtolower(url_title($cat->title)).'-cmdo-'.$cat->id;
        }else{
            $return = 'cursos-de-marketing-digital-online-'.$cat->id;
        }   
    return $return;   
    }
}

到目前为止,他是如此正确,他在网址上标题为“学习”。在我的控制器中,我有一个函数来检查url是否正确并重定向:

    //redirect to real list_route
    if($this->uri->uri_string != $this->learn->url_format_category($category, $lang_domin)) {
        redirect($this->learn->url_format_category(),'location','301');
        exit;
        die($this->learn->url_format_category($category, $lang_domin));

    }

在重定向错误发生时,它是根据url_format_category完成的,但它总是重定向到数组的第一个结果(关于如何生成合格线索的课程,即总是相同的标题),独立于他是一个页面。 如果您还不清楚,我会编辑我的问题。谢谢。

0 个答案:

没有答案