Reduce the PHP logic in view and fix some PHP style.