Yeah had this as well, normally with cavalry as previously mentioned though. I dont think you can do a huge amount about it except a)Hope the charging unit isnt heavily armoured and chews through the phalanx or b) keep a free unit, ideally cavalry, close by to charge the enemy unit in the rear.