'Context' object has no attribute 'view_layer' in Python Script
The manual page you've linked is for Blender 2.81 and is up-to-date. If you're using an older version of Blender you'll have to consult the matching version of the manual. The documentation of bpy.types.Object in Blender 2.79 can be found here.