2
In my model I have this function that defines the url format :
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 checks 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 was wondering if I can create these two functions in Controller (together or separately) and how I could do that. It is possible?
Note: I am using Codeigniter.
Model validating URL? I don’t understand what’s happening in this code...
– Papa Charlie
@Papacharlie In the model you are only setting the default url format. Validation is done in the Controller
– GWER
But URL validation is done by
router
. You are referring to formatting the links to the view composition?– Papa Charlie
That’s right, for the view
– GWER
Well, then I would recommend removing from the model and turning it into a helperpfor direct use by the view. I don’t see this method as part of a model, I see it as part of the scope of a model.
– Papa Charlie
I could do a merge of these functions in Controller?
– GWER
if checks if the Url is in the same format defined by the model, and if it is not it redirects to the correct url.
– GWER
Let’s go continue this discussion in chat.
– Papa Charlie