A website is a Q & A system built with tipask. Today, the customer asked to add a hot question module. Previously, tipask's native modules were used, such as recommendation Q & A and unsolved Q &, it seems that I can only perform secondary development on my own. I found the secondary development about tipask on the Internet ...... So I simply flipped through the tipask code and added the popular question module in my way.
The main functions of tipask are all in the model folder. Find the system core file base. class. php, which has such a function fromcache, used to generate various modules under the function, such as reward questions, wonderful recommendations, etc, what we need to do is add a popular problem module based on the pre-and post-code.
For example, in the code
The code is as follows: |
Copy code |
Case 'notelist': // The announcement list on the right of the homepage |
Add our module code before:
The code is as follows: |
Copy code |
Case 'hotlist': // hot question $ This-> load ('Hot '); // www.111cn.net $ Cachedata = $ _ ENV ['Hot ']-> get_list (); Break; |
Here I followed the recommend Recommendation module and created a new hot. class. php is used to call the above code. In fact, it can be used to call question. class. the list_by_condition function in the PHP file, but passed to question. class. the list_by_condition function in the PHP file can only be added to the SQL where judgment, while the popular module I need only needs to change order by, so I can only create a new hot. class. the PHP file is called by writing the database itself.
The hot. class. Php file is as follows:
The code is as follows: |
Copy code |
Base = $ base; $ This-> db = $ base-> db; } Function get_list ($ start = 0, $ limit = 7 ){ $ Hotlist = array (); $ Query = $ this-> db-> query ("SELECT * FROM". DB_TABLEPRE. "question order by views desc limit $ start, $ limit"); // WWw.111Cn.net While ($ hot = $ this-> db-> fetch_array ($ query )){ $ Hot ['Category _ name'] = $ this-> base-> category [$ hot ['CID'] ['name']; $ Hot ['format _ time'] = tdate ($ hot ['Time']); $ Hot ['Category _ name'] = $ this-> base-> category [$ hot ['CID'] ['name']; $ Hot ['URL'] = url ('question/view/'. $ hot ['qid'], $ hot ['URL']); $ Hot ['image'] = $ hot ['image']? $ Hot ['image']: 'css/default/recomend.jpg '; $ Hotlist [] = $ hot; } Return $ hotlist; } } ?> |
All right, tipask's secondary development of new modules is over. Just follow this example.