php - Display a css class based on a given db record -


i'm using yii i'm trying understand logic implement this, if not yii proficient use help.

we have event types names may containing special characters like:

"amça"

"Áli Çulo"

etc...

i cannot simple grab names , call statically model on view display those, because invalid css class.

the model:

/** * @desc event type name normalized.  * @param int $id * @return object  */  public function geteventtypename($id) {   return normalizer_normalize(self::model()->findbypk($id)->name);  } 

the view:

<p class="event-resume-<?= function_exists('normalizer_normalize') ? eventtype::geteventtypename($data->event->type) : '';?>"></p>    

i've tried user normalizer_normalize but, doesn't work "Áli Çulo" due space between words.

the logic issue:

we can create method says:

if id 1 return constant string named "nameoftype1"
if id 2 return constant string named "nameoftype2"

but not approach because if later have database other id's, correspond other types, need change method again.

what better approach here ?

should provide more information? please advice.

you can hash value of event type , use instead:

<p class="event-resume-<?= md5( $data->event->type ) ?>"></p> 

this might cause .css file less readable, can use comments deal that.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -