Home >Backend Development >PHP Tutorial >Introduction to WASP usage (3)_PHP tutorial
Next, to fill in content for tag arTasks, we need relevant records to already exist in the database. In addition, you have to connect to the database, and by using the WASP data model, you need to use the Wrapper class.
Code:
$oTasks = new TaskWrapper();
$oTasks->findAll();
Creates a data operation object specifically for table Task, and queries all existing records .
Now you can use the following code to loop the output values:
while($oTasks->next())
next() method will return false when there is no record
during the loop process , use an array to save the value for the next display output:
$arTasks[$oTasks->getId()] = $oTasks->toArray();
This code uses a The built-in function getID is used to obtain the primary key in the data table. Recall that when we created the data table, we created a primary key on the field TaskId, so that getI will get the value of the field TaskId. Using this primary key, the current array obtained from the database can be assigned and passed to the object Wrapper. The built-in function toArray() returns the data in the current database in the row format of the array. For example: this array will look like this:
{ 'TaskId' = '1' , 'Name'=>'Buy Groceries'}
The view code does not care about the TaskId field, but should pay attention to: mark { task[Name]} displays on the page the value of the field named Name in the data table.
There is no form here, and there is no need to use the handleEvents() method.
Now you have completed writing the code to output the task list in the display page. If there is no corresponding data in the database, there will be no task output on the page because arTasks is empty, so the code segment in the template: