PHP OOP CRUD Tutorial – Step By Step Guide! Part 9
10.5 Include core.php and read_template.php
The core.php file will be included at the beginning of index.php file. The read_template.php will be included before the layout_footer.php inclusion. The new index.php will look like the following code
|
10.6 Create search.php
This is the most important file of this section. This file will display the records based on a user's search term.
Create a new file and name it "search.php". Open that file and put the following code.
|
10.7 Add search() and countAll_BySearch() methods
Open "product.php" file which is inside the "objects" folder. Add the following methods in the class.
|
10.8 Output
11.0 FILE UPLOAD IN PHP THE OOP WAY
In this section, we will add a "file upload" feature. This feature is included in the LEVEL 2 source code download.
11.1 Change HTML form
Open create_product.php and find the "form" tag. Change that line to the following code. The "enctype" enables the form to submit a file to the server.
|
On the same HTML table, find the closing "tr" tag of the "Category" field. Add the following code. This adds an input field where the user can browse the file he wants to upload.
|
11.2 Set value of "image" field
Open create_product.php and add the new "image" field. The value will be the file name of the submitted file. We used the built-in sha1_file() function the make the file name unique.
Open create_product.php file. Place the following code under $product->category_id = $_POST['category_id']; code.
|