Functions - Model, Controller

2

In my model I have this function that defines the format of the 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/';

    if (is_array($category))  
        $category = (object) $category; 

    if($category->title != '') {
        $return = strtolower(url_title($category->title)).'-cmdo-'.$category->id;
    }else{
        $return = 'cursos-de-marketing-digital-online-'.$category->id;
    }   

    return $return;   
}

And in Controller I have the function that verifies if the url is right and redirects if it is wrong:

if($this->uri->uri_string != $this->learn->url_format_category($data['category'], $lang_domin)) {
 redirect($this->learn->url_format_category($data['category'], $lang_domin),'location','301');
exit;
 }

But now I have to do the same thing with a url that does not contain a Model, so I wanted to know if I can create these two functions on the Controller (together or separately) and how I could do that. Is it possible?

Note: I'm using CodeIgniter.

    
asked by anonymous 08.04.2015 / 20:18

1 answer

1

I think the simplest solution in your case is to create a Model and maintain the pattern you have made in others. But as it was said in the comments by @PapaCharlie you could create a Helper and use it to do this. This link has an example of how to create a Helper, and you can adapt it according to your need.

    
08.05.2015 / 21:14