Home >Backend Development >PHP Tutorial >Introduction to WASP usage (3)_PHP tutorial

Introduction to WASP usage (3)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:02:302081browse

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:

  • {task[Name]} - {task[Due]}

  • There will be no output.
    Once the first piece of data is entered through the page Todo/Entry/, flexy:foreach also has the value of the loop, and the list items will be displayed.
    Picture:
    If you enter more data, more items will be displayed:
    Picture:
    Conclusion
    At this point, a task list applet is completed. We can add and view tasks. As if this is just a very simple convenience, if you want to make it more powerful, have more functions, and design better pages, there will be more work to do. But fortunately, the HTML code is all in the view layer, and we can modify the template arbitrarily without worrying about the PHP code.
    Summary
    Database objects like templates and DB_DataObjects are currently used in PHP, but there is no unified standard applied to products. With the strengthening of object-oriented functions in PHP, it is very convenient to use WASP for PHP development. I hope we can use WASP to develop more, better, dynamic websites. For more information about WASP, please review: WASP documenttation.

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631055.htmlTechArticle Next to fill in the content for tag arTasks, we need to have relevant records in the database. In addition, you have to connect to the database. By using the WASP data model, you need to use the Wrapper class...
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn