my idea is to create zip file contains a new codes, then create external page to download this file and unzip it, for database you can do migration mechanism.
Though I have not done it… some tips to get you started (not related to how Wordpress does it - but how you may want to approach it):
Self-Updating Application: What you need typically needs to be setup as a console application in Yii or have an option to run via console. The reason is you will have physical code files getting over-written OR you may need to use system commands (or modify files), which may not be enabled over Web Server for security reasons.
Having said that technically you could do this on your web app as well - you need to ensure your web server settings are set right. You may also want to check how to trigger a console job from web app.
Auto Updating: You would typically need scripts or packages that auto-update - in Yii2 its straightforward to use composer or bower to auto update your packages. You may also need to use migrations to update your application database.
Maintenance Mode: You would need to set your app to maintenance mode when you are updating - whereby you basically do these things:
backup your application state (files/folders/data)
set a flag to toggle maintenance mode ON. Typically you could do this by creating a .maintenance file on your application root. Your application code should be written to auto-disable itself (reroute to a maintenance error page) when it detects this .maintenance file.
Update Completion: On successful update return a success message and remove the .maintenance file to return back to normal mode. In the eventual case of any error faced during the update, you can restore the application to initial state from the backup and delete the .maintenance file and return/display any errors to the user
You can integrate file transfer protocol support into the application to handle most of the operations remotely, possibly as a separate ftp module. You need to add ftp-specific support to your configuration (ftp username, ftp password, option for using ftp or sftp, etc.). In cases where you need to update the file permissions for existing files, there is a set of 1.x file helpers in the Extensions archive. They would need to be updated to handle current helper file format. Otherwise, adapt the file helpers used for the CodeIgniter framework. These include functions/methods for changing permissions on the fly. ftp is probably the preferred approach because the application itself would have absolute control and ownership over ftp operations. If you were building an application and did not want composer updates for whatever reason, ftp support could also be used to update modules and other elements of the application.
Not sure how Wordpress handles it, but there are numerous options in its particular case because of its blog ancestry. In addition to a ftp scheme, Wordpress could probably also handle the process using REST, SOAP, XMLRPC or any protocol designed to handle remote application control.
I built scripts that package up the application and any database changes (scripts and data in xml formt). It creates a self-extracting executable that I ftp to the server and run it to update the application and database. Sounds simple but much work has gone into developing the scripts.