2. Define a Sharable Model & Migration
Instead of relying on pre-existing database tables, use migrations for portability.
Create Migration for post
Table
Run:
Then, edit migrations/mXXXX_create_post_table.php
:
Run the migration:
Generate the Model
3. Setup Controller and Views
Create Controller
controllers/PostController.php
Create Views
views/post/index.php
views/post/view.php
4. Share the Application
Package it for Sharing
- Exclude Unnecessary Files: Add a
.gitignore
file: - Include
composer.lock
to lock dependencies. - Ensure Migrations Exist (
migrations/
folder).
Sharing Methods
- Git Repository: Push to a Git repo.
- Zip Archive: Compress & distribute.
- Dockerize: Create a
docker-compose.yml
for MariaDB.
5. Install on Another Machine
To deploy:
Visit: http://localhost:8080/index.php?r=post
Now you have a sharable Yii2 app with MariaDB, a basic model, and migrations for easy deployment!
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.