I try to explain myself. I have multiple tables in the project that have a field called "name" or "title". I want to automatically populate another field that has each table called "slug" optimized for friendly urls
For example:
- "name" field: "Tomorrow, I will be in class soon!", It should return
- "slug" field: "tomorrow-I'll-be-in-class-soon"
I have managed to do this by creating a function that we have added in Add Page-> Before record added and in Edit Page-> Before record uodated
$separador = '-';//ejemplo utilizado con guión medio
$originales = 'ÀÃÂÃÄÅÆÇÈÉÊËÌÃÃŽÃÃÑÒÓÔÕÖØÙÚÛÜÃÞßà áâãäåæçèéêëìÃîïðñòóôõöøùúûýýþÿŔŕ';
$modificadas = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
//Quitamos todos los posibles acentos
$url = strtr(utf8_decode($values['name']), utf8_decode($originales), $modificadas);
//Convertimos la cadena a minusculas
$url = utf8_encode(strtolower($url));
//Quitamos los saltos de linea y cuanquier caracter especial
$buscar = array(' ', '&', '\r\n', '\n', '+');
$url = str_replace ($buscar, $separador, $url);
$buscar = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$reemplazar = array('', $separador, '');
$url = preg_replace ($buscar, $reemplazar, $url);
$values['slug']=$url;
My questions are:
- Do I have to put the same code in all the events of all the tables?
- Can you create a global function and then call it on each event? How is it done?
- The result of this function is only seen when the information is saved. Can you see online how the "slug" field is being filled as we write in the "name" or "title" field?
Thank you