Next we will mark arTasks to fill in the content. We need to have related records in the database. In addition, you have to connect to the database and use the WASP data model to use the Wrapper class.
Code:
$ OTasks = new TaskWrapper ();
$ OTasks-> findAll ();
A data operation object exclusive to table tasks is created and all existing records are queried.
Now we can use the following code to loop the output value:
While ($ oTasks-> next ())
The next () method returns false if no record exists.
In the loop process, an array is used to save the value so that the output can be displayed in the next step:
$ ArTasks [$ oTasks-> getId ()] = $ oTasks-> toArray ();
This Code uses a built-in function getID to obtain the primary key in the data table. When we create a data table, we create a primary key on the field TaskId, so that the value of the field TaskId is obtained when getI is created. With this primary key, you can assign values to the current array obtained from the database and pass the Wrapper object. The built-in function toArray () returns data in the current database in an array row. For example, this array will be like the following:
{'Taskid' = '1', 'name' => 'buckets '}
View code does not care about the TaskId field, but note that the tag {task [Name]} is the value of field Name in the data table displayed on the page.
There is no form here, And the handleEvents () method is not required.
Now you have completed writing the code for the task list output on the display page. If no data exists in the database, there will be no task output on the page, because arTasks is empty, so the code segment in the template:
<Li flexy: foreach = "arTasks, key, task"> {task [Name]}-<I> {task [Due]} </I> </li>
There will be no output.
Once the first data Entry is input through Todo/Entry/on the page, flexy: foreach has a cyclic value, and the list item is displayed.
Figure:
If you enter more data, more headers are displayed:
Figure:
Conclusion
Now we have completed a task list applet. We can add and view tasks. This is just a simple example. If you need more powerful functions, more functions, and more pages, you will have more work to do. Fortunately, all the HTML code is in the view layer. We can modify the template at will without worrying about the PHP code.
Summary
Currently, templates and DB_DataObjects database objects have been used in PHP, but there is no unified standard for products. With the strengthening of object-oriented functions in PHP, It is very convenient to use WASP for PHP development. We hope we can use WASP to develop more, better, and dynamic websites. For more information about WASP, see WASP documenttation.