Is it a good practice to return HTML from Php/Mysql function? -
for example have @ below code, return links based on status database.
function favourite_store_link ($store_id, $user_id) { (string) $display_output = null; if ($user_id) { $is_favourite = $this->count_rows('favourite_stores', "where store_id='" . $store_id . "' , user_id='" . $user_id . "'"); $fav_store = ($is_favourite) ? 'remove' : 'add'; $fav_store_msg = ($is_favourite) ? msg_add_to_favourite_stores : msg_remove_from_favourite_stores; $display_output = ' [ <a href="' . process_link('shop', array('user_id' => $store_id, 'fav_store' => $fav_store)) . '">' . $fav_store_msg . '</a> ]'; } return $display_output; } i want ask if ok or must return state of affairs , let template handle rest.
it better split logic , view different parts of code. if return data function have flexibility use function in other places, different views etc.
dividing responsibilities 1 of main principles of maintainable code. can read more here
Comments
Post a Comment