Personal forums developed with smarty
1) it is best to use include to introduce include public files,
For example, the header or image of the page, as well as the display at the bottom
Generally public
2) query, insert, update, and delete a database
The following prompt is displayed after execution:
Controller: for example
$ SQL = "insert into topics (BID, title, content, post_time) values ('$ bid ','". $ _ post ['title']. "','". $ _ post ['content']. "', now ())";
$ Query-> query ($ SQL );
$ Smarty-> assign ('OK', 1 );
V:
{If $ OK} is published successfully!
{Else}
.........
{/If}
3) detection and Determination of client input data
The best use is to determine the reason for JS judgment is that the division of labor is clear and easy to maintain. This is the judgment made on the client.
Second, it is determined on the server that this cost is high and it is easy to reduce the server efficiency, but the accuracy is the highest.
3) Cross-page Data Query
The session storage mechanism is used to temporarily Save the fact sessions on the exaggerated page.
In the controller, determine whether the Administrator is logged on. In the template file output, use: {$ smarty. session. Username}
4) obtain data;
Post is mainly used for data submitted by forms. Get is mainly used to obtain URL data. For example, you can obtain the ID through get to delete or modify a certain information.
5) URL Parsing
GENERAL: <a href = "Edit. php? Id = {$ item. ID} "> modify </a>
<A href = "delete. php? Id = {$ item. ID} "> Delete </a>
In this example, you need to write two templates.
Common URLs;
<A href = "ad_board.php? Action = edit & id = {$ result [u]. ID} "> <B> modify </B> </a>
<A href = "ad_board.php? Action = del & id = {$ result [u]. ID} ")"> Delete </a>
Controller: ---- You can call different methods based on different actions. Write the number of dropped pages on a page and obtain the form at $ _ post ['submit '].
// Delete a plate
If ($ _ Get ['action'] = 'del' & isset ($ _ Get ['id']) {
$ Id = $ _ Get ['id'];
$ SQL = "delete from boards where id =". $ id ."";
// Echo $ SQL;
$ Query-> query ($ SQL );
$ Smarty-> assign ('OK', 1 );
$ Smarty-> display ("ad_userdel.tpl ");
}
// Modify the Section Information
If ($ _ Get ['action'] = 'edit' & isset ($ _ Get ['id']) {
$ SQL = "select * from boards where id = '". $ _ Get ['id']. "'";
$ Q = $ query-> query ($ SQL );
$ Res = $ query-> fetch_array ($ q );
$ Smarty-> assign ('info', $ res );
If (isset ($ _ post ['submit ']) {
$ SQL = "Update boards set board_name = '". $ _ post ['board _ name']. "', board_desc = '". $ _ post ['board _ desc']. "', build_time = now () Where id = '". $ _ post ['id']. "'";
// Echo $ SQL;
$ Query-> query ($ SQL );
$ Smarty-> assign ('OK', 1 );
}
$ Smarty-> display ('ad _ boardedit. TPL ');
}