Codeigniter Lecture Notes 4
Codeigniter Lecture Notes 4
In the Routes.php file, we can disable our specific routing rules and let CodeIgniter do auto-
routing:
A // (double slash) in the code will disable the rest of the line.
$routes->setAutoRoute(true);
you are allowing the CodeIgniter routing system to map URL segments directly to controller class
methods. Setting setAutoRoute(true) is often used for simpler applications where the URL structure
closely matches the controller and method names. For example, if you have a controller named Blog and
a method named show, a URL like example.com/blog/show will automatically invoke the show method
of the Blog controller.
Go to your browser and type the URL localhost/ci/item/test. You should be able to see:
***Take note that since, we have set an Autoroute rule in our Routes.php file, CodeIgniter will
automatically map the URL segment ‘item/test’ with a controller and method whose names closely
match this segment.
1. Go to https://getbootstrap.com/docs/5.3/components/navbar/.
2. Copy the code of the navbar you prefer.
3.
Paste the code in your index.php Views file. You may paste it after the <body> tag.
4. Check your display at the URL localhost/ci/item.
5. In https://getbootstrap.com/docs/5.3/components/navbar/ navigate to the color schemes and
copy a color scheme you prefer.
6. Append the color scheme to the properties in your <nav> opening tag:
<nav class="navbar navbar-expand-lg bg-body-tertiary bg-dark border-bottom
border-body" data-bs-theme="dark" >
Activity 1.
Submit the screenshot of your enhanced localhost/ci/item page that shows the added navigation bar.
CREATING A MASTER PAGE
In web design, a "master page" is a concept that pertains to templates or layout structures used to
maintain consistent design elements across multiple web pages within a website. Also known by other
names like "master template," "master layout," or "master frame," the master page serves as a blueprint
for the overall structure and design of a website.
Benefits:
-consistency of elements like header, footer, navigation menu, and basic page structure among
multiple pages of the website
-ease of maintenance, e.g., design change is done once and is automatically reflected on all
pages using the master page
-code reusability, in which developers create consistent page structure and individual content
pages can focus on their unique content
3. Copy the content of your index.php Views file to your main.php file.
4. Remove the content (which is highlighted part in the figure) from your main.php file.
5. As replacement to the removed content, insert the code
6. Then remove everything from your index.php except for the content.
7. Insert these two lines of codes at the beginning of your index.php.
<?= $this->extend('item/layout/main') ?>
<?= $this->section('content') ?>
Activity 2.
1. Go to https://getbootstrap.com/ and to click on the Docs menu. On the left pane of the page, look for
Components>Buttons. You can see the different button design configurations that you can adopt.
Look for the Button tags section and copy the script for using button classes on <a> elements.
2. Update your index.php Views file with the copied script, see Lines 22-26. We also insert the <tbody>
</tbody> tags, see Line 16 and Line 29.
***Take note we have also applied some button variants like ‘warning’ and ‘danger’ that would change
the color of the buttons.
6. Create controller methods to test your action buttons in your Item.php, see Lines 22 - 40.
7. Save the changes and you should be able to see your test display when you click the buttons.
CREATING DISPLAY FOR ADDING ITEMS
4. Your add.php should now look like this with some text modifications, see Line 6 and Line 7.
5. Update the code of your add() method in Item.php controller, see Line 29.
6. Save the changes and clicking on the Add button should lead you to your add.php page.
7. Likewise, clicking on the Back button leads you back to the index.php (main) page. 8. Go to
https://bootstrapformbuilder.com/ to create the form.
Name field
Price field
Description field
9. From the generated code, copy the code for the form.
***This means we are now able to handle and process the data submitted from the add.php form which
is submitted via the POST method.
7. Notice that the URL will contain an index.php segment after adding an item. To remove, modify the
App.php file in the app/Config directory, see Line 44.
***The URL
Activity 3.
Submit the screenshot of your Add Item page, and the index (List of Items) page that appears after
clicking the Submit button. Attach also your Item.php controller file.