{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Model (ORM)","type":"basic","slug":"mvc-model","excerpt":"","body":"# Model\n\nMVC can be metaphorically related to a TV. **You have various channels, with different information on them supplied by your cable provider (the model)**. The TV screen displays these channels to you (the view). You pressing the buttons on the remote controls affects what you see and how you see it (the controller). -<a href=\"http://stackoverflow.com/questions/2626803/mvc-model-view-controller-can-it-be-explained-in-simple-terms#answer-2626813\">Tilo Mitra</a>\n\nThe model acts as relational mapper for SQL.\n\n## Index:\n- [Generate a Model](#generate)\n- [Learn More](#learn-more)\n\n---\n\n<a name=\"generate\"></a>\n# Generate a Model\n\n```php\nphp brood make:model TicketLogs\n> Crafting Model...\n>    Model has been created!\n```\n\nThe above code will generate a file containing a class that acts as our model, located at ``project-name/components/Model/TicketLogs.php``.\n\n```\n<?php\nnamespace Components\\Model;\n\nuse Components\\Model\\Traits\\Timestampable;\nuse Components\\Model\\Traits\\SoftDeletable;\n\nclass TicketLogs extends Model\n{\n    use Timestampable;\n    use SoftDeletable;\n\n    public function getSource()\n    {\n        return 'ticketlogs';\n    }\n}\n```\n\nWe have the function ``getSource()``, which refers to the table name in our database.\n\nThe above class of code, we're using **Timestampable** and **SoftDeletable** traits which holds an events.\n\nThe **Timestampable** holds the ***created_at*** and ***updated_at***, when we'll be adding or updating a record, it will automatically logs timestamp format.\n\nThe **SoftDeletable** holds the **deleted_at** column of your table, when deleting, it will fill the field.\n\n\n---\n\n<a name=\"learn-more\"></a>\n# Learn More\n\nTo learn more, you can fully review the whole models documentation, we also linked the PHQL language that refers to Phalcon Query Language.\n\n- <a target=\"_blank\" href=\"https://docs.phalconphp.com/en/latest/reference/models.html\">https://docs.phalconphp.com/en/latest/reference/models.html</a>\n- <a target=\"_blank\" href=\"https://docs.phalconphp.com/en/latest/reference/phql.html\">https://docs.phalconphp.com/en/latest/reference/phql.html</a>","updates":[],"order":3,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"56d648d270eba32d006060ae","createdAt":"2016-03-02T01:58:42.578Z","project":"56c111095abfe40d00be875a","version":{"version":"1.3.0","version_clean":"1.3.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["56c1110a5abfe40d00be875e","56c413a254b6030d00ec299d","56c4275048213b1700af6e33","56c42826c0c4630d004e86cb","56c4282cbc41330d009f2607","56c4284ad1f6d91700d3697e","56e271c195d1c60e00a969ee"],"_id":"56c111095abfe40d00be875d","releaseDate":"2016-02-14T23:43:05.566Z","__v":7,"createdAt":"2016-02-14T23:43:05.566Z","project":"56c111095abfe40d00be875a"},"__v":12,"category":{"sync":{"isSync":false,"url":""},"pages":["56d6449db939870b00512c63","56d648d270eba32d006060ae","56d648da70eba32d006060b0","56d648e870eba32d006060b2","56e23cde7d54ba0e00463568"],"title":"Modular-MVC","slug":"modular-mvc","order":2,"from_sync":false,"reference":false,"_id":"56c4275048213b1700af6e33","createdAt":"2016-02-17T07:54:56.500Z","project":"56c111095abfe40d00be875a","version":"56c111095abfe40d00be875d","__v":5},"parentDoc":null,"user":"56c1105874f0b417004baadc","githubsync":""}
# Model MVC can be metaphorically related to a TV. **You have various channels, with different information on them supplied by your cable provider (the model)**. The TV screen displays these channels to you (the view). You pressing the buttons on the remote controls affects what you see and how you see it (the controller). -<a href="http://stackoverflow.com/questions/2626803/mvc-model-view-controller-can-it-be-explained-in-simple-terms#answer-2626813">Tilo Mitra</a> The model acts as relational mapper for SQL. ## Index: - [Generate a Model](#generate) - [Learn More](#learn-more) --- <a name="generate"></a> # Generate a Model ```php php brood make:model TicketLogs > Crafting Model... > Model has been created! ``` The above code will generate a file containing a class that acts as our model, located at ``project-name/components/Model/TicketLogs.php``. ``` <?php namespace Components\Model; use Components\Model\Traits\Timestampable; use Components\Model\Traits\SoftDeletable; class TicketLogs extends Model { use Timestampable; use SoftDeletable; public function getSource() { return 'ticketlogs'; } } ``` We have the function ``getSource()``, which refers to the table name in our database. The above class of code, we're using **Timestampable** and **SoftDeletable** traits which holds an events. The **Timestampable** holds the ***created_at*** and ***updated_at***, when we'll be adding or updating a record, it will automatically logs timestamp format. The **SoftDeletable** holds the **deleted_at** column of your table, when deleting, it will fill the field. --- <a name="learn-more"></a> # Learn More To learn more, you can fully review the whole models documentation, we also linked the PHQL language that refers to Phalcon Query Language. - <a target="_blank" href="https://docs.phalconphp.com/en/latest/reference/models.html">https://docs.phalconphp.com/en/latest/reference/models.html</a> - <a target="_blank" href="https://docs.phalconphp.com/en/latest/reference/phql.html">https://docs.phalconphp.com/en/latest/reference/phql.html</a>