Dedecms weave Dream dede:sql tag, nested PHP syntax in Dedecms and some other methods

Source: Internet
Author: User

Very NB very powerful statement that used him you can write any PHP statement on the template page.

{Dede:Php}
$thisid=$refObj-Fields[' ID '];
$row=$dsql-GetOne ( ' select V_type,video from ' #@__addonarticle ' where aid= ' .< Span class= "PLN" > $thisid );
if ( $row [ "V_type" ]== "SWF" )
{
echo "result One"
else
{
echo "result two"
</script> ';

{/dede:php"

Dedecms there are two tags or more flexible, one is {dede:php} {/dede:php} another is {Dede:sql} tag, {dede:php} tag comments to be used to write PHP code in the template, {Dede:sql} Mainly used to invoke SQL, the following is to describe how these two tags in the end how to use. This article is transferred from the Baidu space an article.
{Dede:sql} Usage of tags
SQL tags can be called a universal tag, query the database to output it, here are some about the use of this tag:
1. Used to output statistical content, this is good, for example, we have to count the total number of articles issued, the idea is to output dede_addonarticle This article add the total number of table content can be.

123 {dede:sql sql="SELECT COUNT(*) AS nums FROM dede_addonarticle"} [field:name = "nums"/] {/dede:sql}


2. Use ~field~ for special queries, such as before the forum many members need to do an output of the current post members of the relevant content, before using SQL or arclist tag is not possible, because each content is different, here we use 5.5 of SQL statements to do a demonstration.
We first add the following label to the corresponding position in the article template

123 {dede:sql sql="SELECT * FROM dede_archives WHERE writer=~writer~"} [field:id/], {/dede:sql}


This is put on the Article_article.htm page, will retrieve the current member published related articles, where the ~ writer~ will be based on the current content of the environment variables to be replaced before the query execution.
This appears in the SQL statement of the conditional query ~ writer~, that is, $refobj->fields[$value] This inside the relevant content
Using PHP in Templates
Many people want to weave a dream template tag can be more flexible, to join the function that can run PHP, here in Dedecms V5.5 added a can execute PHP special tag {dede:php}{/dede:php}, this tag can execute PHP statement.
Here are a few common examples:
1. The simplest output content:

123456 {dede:php} $numA = 1; $numB = 2; echo $numA + $numB;   {/dede:php}

In {dede:php} want to output information can be directly used print, echo, such as printing out to assign value to @me invalid

The content of this output is the result of the calculation:
3
2. Output a single content with SQL query

1234 {dede:php} $row = $dsql->GetOne(‘select id,typename from dede_arctype where id=2‘); print_r($row); {/dede:php}


The content of this output is
Array
(
[id] = 2
[TypeName] = Q
)
3. Get the variables for the current page
For example, we enter the [Template]-[Global tag test] in the system background, we fill in the following content in the code:

1234 {dede:php} print_r($refObj->Fields);   {/dede:php}

In PHP you want to get Dede a field value can use $REFOBJ->fields object to get included in get title = = $refObj->fields[' title ']

If the environment variable remains the default, that is, "do not use Environment ID", we will see the following result:

1234567891011 Array ( [typeid] => 0 [phpurl] => /plus [indexurl] => / [templeturl] => /templets [memberurl] => /member [specurl] => /special [indexname] => 主页 [templetdef] => /templets/default)


Let's change the environment variable test to see, here in my local column for testing:

1234567891011121314 Array ( [id] => 3 [reid] => 0 [topid] => 0 [sortrank] => 1 [typename] => 产品 [typedir] => {cmspath}/product … … [indexname] => 主页 [templetdef] => /templets/default[position] => 主页 > 产品 > [title] => 产品 )


This retrieves the local variables of the current page, and then we can combine the preceding SQL statements to invoke the contents of different columns according to different environment IDs.
For example:

12345 {dede:php} $thisid = $refObj->Fields[‘id‘]; $row = $dsql->GetOne(‘select id,typename from dede_arctype where id=‘.$thisid); print_r($row); {/dede:php}


This is to invoke the title of the current column, which functions like {dede:field.typename/}

Dedecms weave Dream dede:sql tag, nested PHP syntax in Dedecms and some other methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.