A controller script catalog_controller.php
gets created in the controllers
directory. View templates _form.phtml
, edit.phtml
, index.phtml
, add.phtml
, and show.phtml
get created in the views
directory.
Modify the _form.phtml
view template. Add the following line as the first line in the _form.phtml
form:
<p><label for="catalog_id">Id:</label><br/> <?= text_field("catalog", "id") ?></p>
The default URL for a URL action is http://localhost/controller/action
. Custom URLs may also be defined in the config/routes.php
file. For example, the add controller action of catalog
controller may be invoked by specifying a custom router in the config/routes.php
file. With the custom router the url http://localhost/catalog
invokes the add
action of the catalog
controller.
$router->connect( "catalog",array(":controller" => "catalog",":action" => "add") );
Next, we shall use the scaffolding for the catalogs
table to add a new catalog entry. Invoke the index
controller action with the URL http://localhost/catalog/index
. The catalogs listing gets displayed. The Show, Edit, and Delete links are for displaying, editing and deleting a catalog entry respectively. To create a new listing click on the New hyperlink.
In the New catalog view template, create a new catalog entry and click on Create.
A new catalog entry gets added to the database table catalogs and gets listed in the "Listing catalogs".
There you have it - that's how you create a PHP MVC CRUD application without using too much PHP code thanks to the PHP On Trax Framework. You can download code for the project here.®