A multi-phase model for simulations of galaxy formation