The mayor may appoint, upon the recommendation and approval of appointment by the city council, a city attorney whose compensation shall be established by the city council by ordinance. The city attorney shall be responsible for representing and defending the city in all litigation in which the city is a party; may be the prosecuting officer in the municipal court; shall attend the meetings of the council as directed; shall advise the mayor, city council, and other officers, and employees of the city concerning legal aspects of the city's affairs; and shall perform such other duties as may be required of him or her by ordinance or by virtue of his or her position as city attorney.