Dedecms for ADMIN5 Comprehensive application lecture

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

First I briefly introduce myself, I am the dream of the official team, contact Weaving Dream has more than 2 years, has been in the forum to do the owner, know a lot of love to weave a dream friend, then joined the Dream team, found that this is a vibrant, passionate and learning place, This time by the Webmaster network invited to give you a dedecms program of lectures.

Because this is mainly the lecture, lacks the system the training content, this lecture I will weave the Dream Technical Forum The more common question to organize, and unifies some other aspects application content to supplement, lets everybody understand the dedecms procedure the use.

Security settings

The first is the security of the program, here are mainly some owners of independent servers, if their own system security deployment above some experience that should be no problem, there are some webmaster without system security deployment experience, and now hanging horse rampant, so many people are worried that the official earlier on the issue of a Dedecms v5.3/v5.5 Security Settings Guide The theme of the post, address: http://bbs.dedecms.com/172474.html, which says how to configure the server environment in win serv environment.

However, the paper mentions the directory of Dream-weaving, here I have a description of the entire system file directory: http://bbs.dedecms.com/178324.html, of course, if you install a module will be appropriate to add a number of directories, such as module group, ask and so on.

{dede:sql} label usage

The SQL tag can be called a universal tag, and the query database outputs it, and here's how to use the tag:

1. Used to output statistical content, this is good, for example, we have to count the total number of articles sent, the idea is to output dede_addonarticle This article additional table content can be.

{dede:sql sql= ' select COUNT (*) as Nums from dede_addonarticle}

[Field:name = "nums"/]

{/dede:sql}

2. Use ~field~ to make special inquiries, such as before the forum many members need to do an output of the current post members of the relevant content, the previous use of SQL or arclist tag is no way to achieve, because each content is different, here we use 5.5 of the SQL statement to do a demonstration.

We first add the following label to the corresponding position in the article template

{dede:sql sql= "select * from Dede_archives WHERE writer=~writer~"}

[Field:id/],

{/dede:sql}

This is placed on the article_article.htm page, will be retrieved from the current membership of the relevant articles, where the ~ writer~ will be based on the current content of the environment variables to replace and then execute the query.

Here in the SQL statement in the conditional query of the ~ writer~, that is, $refobj->fields[$value] This inside of the relevant content

Using PHP in Templates

Many people want to dream of the template tags can be more flexible, add the ability to run PHP, here in Dedecms V5.5 in a special tag can be executed PHP {dede:php}{/dede:php}, this tag can execute PHP statements.

I'll give you a few common examples here:

1. The simplest output:

{dede:php}

$numA = 1;

$numB = 2;

echo $numA + $numB;

{/dede:php}

The content of this output is the result of the calculation:

3

2. Combine SQL query output single content

{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] => questions and Answers

)

3. Get the variable for the current page

For example, we enter the system backstage [Template]-[global tag test], we fill in the following content in the code:

{dede:php}

Print_r ($REFOBJ->fields);

{/dede:php}

If the environment variable remains the default, that is, "do not use the environment ID," We see the following results:

Array

(

[typeID] => 0

[Phpurl] =>/plus

[Indexurl] =>/

[Templeturl] =>/templets

[Memberurl] =>/member

[Specurl] =>/special

[IndexName] => Home

[Templetdef] =>/templets/default

)

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

Array

(

[ID] => 3

[Reid] => 0

[Topić] => 0

[Sortrank] => 1

[TypeName] => Products

[Typedir] => {cmspath}/product

... ...

[IndexName] => Home

[Templetdef] =>/templets/default

[Position] => Home > Products >

[Title] => Products

)

This will retrieve the current page of the local variables, and then we can combine the previous SQL statements to implement different environment ID based on the content of different columns.

For example:

{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/}

Write your own label and let people say it.

Dedecms from V5.3 to support their own extended tags, but a lot of new people rarely use that thing, today I would like to briefly describe how to write their own call tag.

We need to know the contents of the extended tag and the file name, first of all, the extended label is stored in the/include/taglib directory, the name is in the "tag name. lib.php" format, such as {dede:channel/} The label corresponds to the channel.lib.php file.

We can look at an example tag: demotag.lib.php

  

if (!defined (' Dedeinc '))

{

Exit ("Request error!");

}

Function Lib_demotag (& $ctag,& $REFOBJ)

{

Global $dsql, $envs;

Property handling

$attlist = "row|12,titlelen|24";

Fillattsdefault ($ctag->cattribute->items, $attlist);

Extract ($ctag->cattribute->items, Extr_skip);

$revalue = ';

The code you need to write, you can't use the syntax like ECHO, to pass the final return value to $revalue

//------------------------------------------------------

$revalue = ' Hello word! ';

//------------------------------------------------------

return $revalue;

}

?>

We log into the system background [Template]-[Global label Test] run {dede:demotag/}, showing the following results:

Here we know, in fact, the content of the tag generated is actually a return value of this function, where the content returned is a string, that is, the function return $revalue, the $revalue need to be processed after the generated string.

$attlist = "row|12,titlelen|24"; This is the list of attributes, which, after being processed directly, generates variables and replicates, and we can test the following modifications:

$revalue = ' Hello word! ';

$revalue. = "
Row: ". $row."; Titlelen: ". $titlelen;

So we can see that this property has been created and assigned a value.

We can then further modify the label.

For example, we need to write a tag to query the content page of the relevant article, the function is similar to the SQL tag above the SQL, but here we will be divided into a label.

We can create a new tag, such as WRITERARC, so we need to build a writerarc.lib.php, and then imitate Demotag to write functions, note that we need to modify

Function Lib_writerarc (& $ctag,& $REFOBJ)

Next we can write query statements and the related functions on the underlying template processing

$revalue = ';

$innertext = $ctag->getinnertext ();

$CTP = new Dedetagparse ();

$CTP->setnamespace (' field ', ' [', '] ');

$sql = "SELECT * from Dede_archives WHERE writer= ' {$refObj->fields[' writer ']} ' limit 0, $row";

$innertext This is used to get the underlying template for the label, $CTP create a variable to work with in the underlying template and handle the substitution. We write our SQL statements based on the attributes we get, where we use limit 0, $row, so that we can determine the number of queries based on $row.

Of course we can get more properties so that our tag is more powerful, for example, we can add related attributes similar to arclist and process them in functions, but this requires a certain PHP base.

Next we handle the SQL and output variables by executing the query:

$dsql->execute (' Me ', $sql);

while ($rs = $dsql->getarray (' Me '))

{

Processing query variables based on attributes

$rs [' title '] = Cn_substr ($rs [' title '], $titlelen);

Get the underlying template

$CTP->loadsource ($innertext);

foreach ($ctp->ctags as $tagid => $ctag) {

if (!empty ($rs [Strtolower ($ctag->getname ())]) {

$CTP->assign ($tagid, $rs [$ctag->getname ()]);

}

}

Processing results based on underlying templates and query variables

$revalue. = $ctp->getresult ();

}

This allows us to replace the query results with the related variables that appear in the underlying template, and then generate an output string that stores all the string information in $revalue.

Return this value finally $revalue;

The entire document reads as follows:

  

if (!defined (' Dedeinc '))

{

Exit ("Request error!");

}

Function Lib_writerarc (& $ctag,& $REFOBJ)

{

Global $dsql, $envs;

Property handling

$attlist = "row|12,titlelen|24";

Fillattsdefault ($ctag->cattribute->items, $attlist);

Extract ($ctag->cattribute->items, Extr_skip);

$revalue = ';

$innertext = $ctag->getinnertext ();

$CTP = new Dedetagparse ();

$CTP->setnamespace (' field ', ' [', '] ');

$sql = "SELECT * from Dede_archives WHERE writer= ' {$refObj->fields[' writer ']} ' limit 0, $row";

$dsql->execute (' Me ', $sql);

while ($rs = $dsql->getarray (' Me '))

{

Processing query variables based on attributes

$rs [' title '] = Cn_substr ($rs [' title '], $titlelen);

Get the underlying template

$CTP->loadsource ($innertext);

foreach ($ctp->ctags as $tagid => $ctag) {

if (!empty ($rs [Strtolower ($ctag->getname ())]) {

$CTP->assign ($tagid, $rs [$ctag->getname ()]);

}

}

Processing results based on underlying templates and query variables

$revalue. = $ctp->getresult ();

}

return $revalue;

}

?>

Next we'll test our tag, we modify the article_article.htm template and add the following tag code inside:

{dede:writerarc row= ' titlelen= ' 6 '}

[field:title/]

{/DEDE:WRITERARC}

Through the Dynamic browsing page to view debugging http://www.dedecms.com/plus/view.php?aid=3, we will find that the tag is working and outputting our content.

At this point we have completed the preparation of the label, which mainly involves PHP, MySQL, a lot of knowledge, need to have some relevant aspects of the basis to be able to write labels, of course, here is just a simple example of label development, there are many things can be developed.

Related Article

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.