PHPCMS search Function implementation

Source: Internet
Author: User

This article introduces the content is about PHPCMS search function realization, has certain reference value, now shares to everybody, has the need friend can refer to

Recently in doing a portal, using the PHPCMS search function, has always wanted to realize this aspect of function, but suffer from static not down to study the principle of phpcms, today through this blog record my analysis of the process, on-line information is relatively fragmented, see is always foggy, Here is a summary of the comparison system.

Files related to the search function

The background template for the Phpcms Search feature is located under: Phpcms\modules\search path, There is a file named index.php under this path, there are some methods used to show the results of the search, such as our usual Init method, from the index.php construction method
$this->db =pc_base::load_model (' Search_model '); you can see that index.php used the database prefix _search name of the table
The front-end template for the Phpcms Search feature is located at: Phpcms\templates\default\search, where there are four files under that path, are index.html,footer.html,header.html and list.html, where index.html indicates that there are no search results when the display page is invoked, header.html and footer.html indicate the header of the output search results to and footer section, list.html represents the display page that is called after the search results

Modifying the backend Template

For the search function of Phpcms, the main use is MySQL match against Fuzzy query function, but this function for query contains the content of Chinese information is not correct, support and bad, so I put this part of the code is blocked, specific shielding method, open phpcms\ modules\search\index.php file, find about 84 lines and comment out the following code:

If the word breaker result is empty if (!empty ($segment _q)) {    $sql = "' SiteID ' = ' $siteid ' and ' typeid ' = ' $typeid ' $sql _time and MATCH (' data ') A Gainst (' $segment _q ' in BOOLEAN MODE) ';} else {    $sql = "' SiteID ' = ' $siteid ' and ' typeid ' = ' $typeid ' $sql _time and ' data ' like '% $q% '";}

Add the following code after this code:

$sql = "' SiteID ' = ' $siteid ' and ' typeid ' = ' $typeid ' $sql _time and ' data ' like '% $q '";

Modifying front-end code

Modification of front-end code we can refer to the phpcms\templates\default\search\index.html file, view the original index.html file, find the code associated with the query feature form submission as shown in:

<form name= "search" type= "get" > <input type= "hidden" name= "M" value= "    Search "/> <input type=" hidden "name=" C "value=" index "/> <input type=" hidden "name=" a "value=" Init "/> <input type= "hidden" name= "typeID" value= "{$typeid}" id= "typeID"/> <input type= "hidden" name= "SiteID" value = "{$siteid}" id= "SiteID"/> <p class= "sr_frm" > <p class= "Sr_frm_box" > <p C                  lass= "Sr_frmipt" ><input type= "text" name= "q" id= "Q" class= "IPT" > <p class= "sp" id= "ACA" > </p><input type= "Submit" class= "ss_btn" value= "Search" > </p>                  ; </p> <p id= "Sr_infos" class= "Wrap Sr_infoul" > </p> </P></FORM&G t; 

In this part of the code, the type attribute of input hidden is added to the URL by default when the form is submitted, which is not submitted by our form, for example, in my own case, I include the search button URL: http://localhost/ startwill/index.php?m=content&c=index&a=lists&catid=41, when I enter the product two characters in the search box, the URL after the jump is: http://localhost/ Startwill/index.php?m=search&c=index&a=init&typeid=3&siteid=1&q= products, where m, C and a, typeid, The value of SiteID is we submit through the way of hidden, and the value of Q is through the search box to enter, we in our own page when used, can be modeled above this code.

To modify the display code

The display code of the

Phpcms can be implemented in reference to phpcms\templates\default\search\list.html, which can be list.html by {loop

R} to get the result value of the search, $data the content fields stored here are as follows:

with these field information, we can display the page in our own list.html.
It is important to note that when we write code in our own list.html, we can use loop loops, but do not use data stores its own traverse to Value, the value of the search assignment is overwritten, and the entire page will show you the value assigned to it.


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.