Use functions in templates,I believe most tper know and have used it.


How to get username

function get_username ($uid) {
  $row=m ("user")->getbyuid ($uid);
  return $row ["username"];

Display username by uid in template

<volist name="rows">
  <td>{$row.uid | get_username}</td>

I believe everyone should use this method, right?There are two disadvantages to this usage:

1. Too many database operations;

2. The location of the data operation is unreasonable,The database connection is too long.


1. Make database operations that can be merged as much as possible;

2. Data operations should be kept in the data layer.Avoid manipulating the database in views as much as possible,It is recommended to execute mysql_close () before the view starts to disconnect the database connection.

  • Previous asp knowledge finishing notes 3 (question and answer mode)
  • Next DataGridView expansion and contraction function implementation