Codeigniter - in the view or in the controller? Is this correct? Or am I overloading the responsibilities of the view?

&lt;table class="table table-striped table-hover"&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Estado&lt;/th&gt;
                &lt;th&gt;Prioridad&lt;/th&gt;
                &lt;th&gt;Responsable&lt;/th&gt;
                &lt;th&gt;Categoría&lt;/th&gt;
                &lt;th&gt;Solicitud&lt;/th&gt;
                &lt;th&gt;Creado&lt;/th&gt;
                &lt;th&gt;Cerrado&lt;/th&gt;
            &lt;/tr&gt;
    &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;?php 
                 $class = '';
                 $label = '';
                 foreach ($solicitud as $key =&gt; $value) {
                     if( $value['priority'] &gt; 0 &amp;&amp; $value['priority'] &lt; 4 ) $class = 'badge-important';
                     if( $value['priority'] &gt; 4 &amp;&amp; $value['priority'] &lt; 7 ) $class = 'badge-info';
                     if( $value['priority'] &gt; 7 ) $class = 'badge-warning';

                     if( $value['id'] == 1 ) $label = 'label-info';
                     if( $value['id'] == 2 ) $label = 'label-success';
                     if( $value['id'] == 3 ) $label = 'label-danger';

                    echo '&lt;tr&gt;';
                    echo '  &lt;td&gt;&lt;span class="label label-sm '.$label.'"&gt;'.ucfirst($value['status']).'&lt;/span&gt;&lt;/td&gt;';
                    echo '   &lt;td&gt;&lt;span class="badge '.$class.' "&gt;'.$value['priority'].'&lt;/span&gt;&lt;/td&gt;';
                    echo '   &lt;td&gt;'.$value['sname'].' '.$value['last_name'].'&lt;/td&gt;';
                    echo '   &lt;td&gt;'.$value['name'].'&lt;/td&gt;';
                    echo '   &lt;td&gt;'.$value['message'].'&lt;/td&gt;';
                    echo '   &lt;td&gt;'.$value['created'].'&lt;/td&gt;';
                    echo '&lt;td&gt;'.(( $value['closed'] )  ? $value['closed'] : 'pendiente').'&lt;/td&gt;';
                    echo '&lt;/tr&gt;';

                 } ?&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
These 0, 4 and 7 means nothing to any code reader, nor 1, 2 and 3 for the label.

Move this logic in the controller and consider using ENUMs in your controller class i.e.:

const BADGE_IMPORTANT = 0;
const BADGE_INFO = 4;
const BADGE_WARNING = 7;


This way it will be more readable for the one who will read and change it later, also it will became less hard changable and more reusable.

Also, try to not echo HTML, I mean, use PHP blocks only when you have PHP in it. HTML should be outside:

&lt;?php foreach ($solicitud as $key =&gt; $value): ?&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;span class="label label-sm&lt;?=$label;?&gt;"&gt;&lt;?=ucfirst($value['status']);?&gt;&lt;/span&gt;&lt;/td&gt;
              &lt;td&gt;&lt;span class="badge &lt;?=$class;?&gt;"&gt;&lt;?=$value['priority'];?&gt;&lt;/span&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?=$value['sname'].$value['last_name'];?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?=$value['name'];?&gt;&lt;/td&gt;
               ....
          &lt;/tr&gt;
&lt;?php endforeach; ?&gt;