Core and service, public model, plug-ins, widgets, third-party class library together constitute a big foundation of the system, all other applications are built on it. The term explains the core: derived from the thinkphp framework, which provides core functions such as MVC separation, underlying database support, and provides a number of convenient class libraries and libraries for use by other parts of the system. Located in the/core/directory. Services: A set of globally common class libraries that enable encapsulation of specific functions. Located in the/addons/services/directory, such as mail, user authentication (Passport), etc. Public model: A set of global generic models. Located in the/addons/models/directory, such as the attachment Model (Attachmodel), the regional model (Areamodel), and so on. Plug-in: A program file added to implement a function. Located in the/addons/plugins/directory, including third-party platform landing plug-ins and medals two kinds. Widget: A set of code blocks that can be called on any HTML page. Located in the/addons/widgets/directory, including comments (Comment), select Friends (selectfriend), and more. Third-party class libraries: Other open source third-party class libraries. Located in the/addons/libs/directory, such as Phpmailer. Application: A standalone module that implements a specific function, built on the system structure described above. Located in the/apps/directory, such as log (blog), album (photo) and so on. API: Application Programming Interface (application Programming Interface). Located in the/api/directory, such as Weibo API, user profile API, etc. --------------------------------------------------------------------------------------------------------------- Although-----------------------Weibo Weibo is also a system-independent application (1), it is also responsible for the core application of the system. Many of the system elements are built entirely on Weibo applications, such as Weibo widgets (i.e. "share"), which operate directly on Weibo, while WAP applications are fully using the microblog API architecture. Another special case in roaming platform system applications is roaming apps. Roaming apps originate from the Hong Sing roaming platform, which is completely different from the directory structure of the Thinksns because the URL of the roaming platform is generated according to the Uchome directory structure, and also takes into account the portability of the roaming platform. So the integrated roaming application does not take the standard ThinkSNS2.0 core, but instead uses a minimal version of the framework that has been implemented within the roaming application. If you are a templateDevelopers, you have to pay special attention! Because after you modify the header and left pages in the public directory, you also modify the head and left side (in the/apps/myop/themes/classic/directory) under roaming. --------------------------------------------------------------------------------------------------------------- ---------------------------directory Structure Thinksns2.0├─_runtime-------------run-time cache ├─addons-------------Extension library │├─libs--------- ----third-party class library │├─models-------------public model│├─plugins-------------plug-in ││├─login-------------third-party platform login plugin ││├─medal- ------------Medal ││└─tags-------------label │├─services-------------system service │└─widgets-------------System WIDGET├─API----- --------API Library ├─apps-------------System application │├─admin-------------Management background │├─home-------------Home app │├─myop------------- Roaming app │├─wap-------------Mobile WAP End │└─weibo-------------Weibo application ├─core-------------core │├─sociax-------------system core File │├─ thinkphp-------------thinkphp core │└─sociax.php-------------core boot file ├─data-------------site data ├─install-------------system Installation file ├─public│├─admin-------------Management background │├─js-------------System JS Library │└─tHemes-------------System Template ├─access.php-------------node permission control file ├─cleancache.php-------------cache cleanup File ├─config.inc.php---- ---------Site profile ├─index.php-------------site portal File ├─shorturl.php-------------short address file └─thumb.php------------- Automatic thumbnail generation file---------------------------------------------------------------------------------------------------------------- --------------application Architecture and directory structure application directory location and structure: thinksns2.0├─apps├─app├─appinfo-------------installation information, loading and unloading executable files, icon ├─common-------- -----function Library common.php├─conf-------------project configuration config.php├─language-------------notifications, Dynamic language pack ├─lib│├─action------------- Operation Class Library │├─model-------------Model class Library │└─widget-------------plug-in library └─tpl-------------template, CSS, JS file entrance file ThinkSNS2.0 There is only one public portal file, that is index.php. URL pattern URLs in the Thinksns directory are accessed index.php?app=app_name&mod=action&act=function The function library applies its own library of functions to the common/common.php in the application directory, and the function is loaded with the app, and can be called arbitrarily within the app. System functions Library See the "Library of Functions" in the Appendix. Template [......] 10/32 The applied style files are stored uniformly in the public/directory under the TPL, through: /PUBLIC/XXX.CSS reference, the application of JS file unified into the application under the tpl/under the public/js/directory, through: /public/js/xxx.js Reference. --------------------------------------------------------------------------------------------------------------- -----Development Guide 3.1 naming and coding specifications for reference thinkphp: http://thinkphp.cn/Manual/203.2 using function libraries, class libraries, and widgets using the System functions library system functions are located in/core/ Sociax/functions.php and/core/sociax/extend.php files, which are global valid functions, can be called directly. How to obtain the user nickname: $uname = GetUserName ($uid), using the service service located in the/addons/services/directory, through the service (' ServiceName ')->method ($param); To use the service. such as verifying that the user is logged on: $is _logged = Service (' Passport ')->islogged (), using the public model public model in the/addons/models/directory, through the model (' ModelName ')->method ($param) to use the public model. For a list of regions: $area _list = Model (' area ')->getarealist (), using Widgetwidget in the/addons/widgets/directory via W (' Widgetname ', Array (' param ' = ' = ' value ') to invoke the widget. The generic widget is used in the page, so the calling method is: {: W (' Widgetname ', 11/32array (' param ' = ' value ')}). If you're showing someone you might know on the page: {: W (' Relateduse ', Array (' uid ' = ' 1 ')} Use third-party class libraries third-party class libraries are generally placed in the/addons/libs/directory, before use Include_ Once functions such as the introduction of files.3.3 Using Popup, prompt message, editor in the world of ThinkSNS2.0, the jquery library is our default JS frame, which is automatically loaded on the page header. ThinkSNS2.0 encapsulates pop-ups, cue messages, and kissy editors on a jquery basis, and this section focuses on how they are used (the official jquery Library document: Http://docs.jquery.com/Main_Page). Pop-up Windows 2 pop-up Windows 2, the popup window contains at least the title, the Close button and the content of the three parts, in order to ensure the consistency of user operations, generally in the Content section to add the "OK" and "Cancel" button. Popup Window Call method: Place the contents of the popup window in Your_url. Note: the "OK" and "Cancel" buttons are also part of the content! Close the popup window: 12/32 hint message figure 3 Prompt message Call method: Editor Editor related JS automatically loaded on the page header, only need to call E = Kissy. Editor ("Idoftextarea"); To complete the loading of the editor. such as: 3.4 thinkphp Development Guide thinkphp Official Documentation – Development Guide: Http://thinkphp.cn/Manual/50ThinkPHP official Documentation – Template guide: http://thinkphp.cn/Manual/ 1943.5 application Development Look at the previous introduction and explanation, I believe everyone has been stirring. This chapter takes the development of the gift application as an example to show you the whole process of developing an application. If you are a thinkphp developer, you will find that developing an application is actually creating a new project, which is also the charm of ThinkSNS2.0: application independence. 13/32 development process ThinkSNS2.0 general flow of application development: 1. Create a database and data table (no database operations can be skipped) 2. Project name and create project directory 3. Create the Controller Class 4. Create model Class 5. Create a template file 6. Run and debug development requirements and development goals our gift applications need to implement the following features: 1. Users can send gifts to people or fans who are interested in 2. Users can see all the gifts they send out 3. Users can see all the gifts that others give themselves 4. Users can give gifts to friends 5. When a user sends a gift, they can send a notification message at the same time 6. Users can send a gift after the successful delivery of Weibo share message 7. Administrators can add, modify, delete gifts and gifts in the background 8. Administrator can configure gift points in the background consumption type: Points? Experience? 9. Achieve Perfect integration consumption function, if the user points are not enough to create a data table according to the above requirements analysis, we need to design three data tables, one to save the gift of the classification information, the otherTo save the information for the gift, and one to save the user's gift record. Add Data table Note the table naming format: database table prefix + table name, where the database table prefix in the config.inc.php Db_prefix constant has been defined. Add a Gift Classification table: Field type description Idintnamevarchar class name Statustinyint is enabled 0 disabled 1 enabled (default) Ctimeint creation time increased by two default categories: popular gifts, Latest Listings Add gift information table: Field type description idintcategoryidint Category ID, Idnamevarchar gift name corresponding to the above classification table Numint stock 14/ 32priceint Price Imgvarchar gift picture Statustinyint whether to enable 0 Disable 1 enable (default) Ctimeint creation time Here we will of course have to prepare part of the gift, that is, the initialization of the gift information. Add Gift Record table: Field type description Idintfromuseridint giver idtouseridint gifts giftpriceint price Giftimgvarchar gift Picture Sendinfotext additional information Sendwaytinyint gift way: 1 Public 2 privately 3 anonymous ctimeint created time to this, data sheet design completed. The Install.sql file in the/gift/appinfo/folder under the application directory contains the SQL statements for the above table and the inserted predefined data. Create an app catalog Figure 4 application directory structure as shown, we will first add the Gift directory gift under the/apps/directory, and then create the directory shown in the/apps/gift/directory (note case). Application directory Lib: The file in the application directory is the action controller and model models. Application Template Catalog TPL: Since this gift application has only one set of templates, we create the default template directory default/directly in the tpl/directory, and then add the index template and a public template directory public/in the default/directory that we need. Common Functions Directory Common: Here can store the public function of this application, the file name is common.php, the file will be loaded automatically during the execution, these functions can be used directly in action/and model/files, no need to introduce the file again. We can also use public functions directly in ThinkSNS2.0, which are stored in fuctions.php and extend.php under the 15/32/core/sociax/folder, including our most commonly used data processing orData obtained, such as the H (), t () filter function, the GetUserName () function (called in the template file is: {$userId |getusername}), the Getuserface () function, and the Friendlydate () function ( Usage with GetUserName ()). The above several functions recommend everybody to use. Application Configuration Directory conf: If the application needs to modify the system default constants or add some of the configuration parameters needed in the project, you need to create a configuration file with the name config.php in the project's conf/directory, and the file will be loaded automatically. The common functions directory and the application configuration directory are not required directories, depending on whether the application development decision is required. Only public function folders are used in this gift development. Language Directory Language: The system notification template and the dynamic template used to save the app. The system notification template will be used in this gift development. In the language/directory, create the Chinese Language Pack directory cn/, and then add the notification template file notify.php (dynamic is the same, just the file name is: feed.php). Install package Directory appinfo: Application Install/uninstall operation in Thinksns background, must contain info.php file (to obtain application information), if contain install.php or uninstall.php file, it will be called automatically when the app installs and uninstalls. Start programming the public function layer in the common/directory, create a new common.php file (note the case of the file name), write the required function, such as get the function to apply the configuration parameters: Functions GetConfig ($key =null) {[...]} For detailed code, see the file. The functions in this file can be used directly in the action/, model/, and tpl/directories. model layer in the lib/model/directory, create a new three files giftcategorymodel.class.php,giftmodel.class.php And UserGiftModel.class.php, create the code as follows: Class Giftcategorymodel extends model{}class Giftmodel extends model{}class Usergiftmodel extends model{} with the above steps, we have now established an association between the database table and the model class. In the project's action class and model class, you can already work directly with the database. Some people are used to encapsulating some methods in the model class, which is more in line with the MVC specification.There are also some people who are accustomed to writing methods in action to facilitate the reading of the program, which mainly depends on personal habits. This development will write the basic method into the model layer. For detailed code, see the appropriate file. action layer in the lib/action/directory, build the IndexAction.class.php, and create the code as follows: Class Indexaction extends action{} detailed code to participate in the file. Template Layer 16/32 We need two folders in the tpl/default/directory: Index and public. The index folder name corresponds to the IndexAction.class.php file, which means that the files below the index folder are all the templates required for the IndexAction.class.php file. Application of public files we generally put in the tpl/default/public/directory, such as gift application of gift pictures, JS files, CSS files, application header file _mainnav.html and so on. Of course, the settings for these directories are entirely up to the developer's discretion, as long as the path to the calling file is guaranteed to be correct. Let's take a look at the general structure of the ThinkSNS2.0 template file, developers introduce the application of their own style files and JS files can be directly in the canvas layer to add the corresponding display code: [......] For more information, please refer to the specific code. Here are some of the code for Learning value in the template file. 1. ThinkSNS2.0 full use of jquery technology, jquery is a good lightweight JS framework, can help us to quickly develop JS applications, and to a certain extent, change the way we write JavaScript code habits. THINKSNS2.0 has introduced the jquery library in the header file, and developers do not have to introduce it repeatedly. 2. tpl/default/index/directory of the index.html file, which is the Gift center template, which choose to send friends to use the friend selection widget, only need to add {: W ("Selectfriend")} in the template, and then use the $_post [' Fri_ids '] will be able to get the selected friend Id.3. Because we use the Findpage () method to get the list of received and sent gifts, the returned data already has a paging variable, as long as the template is appropriate to add the following code: {$gifts. html}17/32 add points consumption function above the program basically completed the full operation of the gift , then we need to increase the point consumption function. As for the gift consumption of the integral type, is the points or experience, can be set in the background, detailed see the background program instructions. First, in the Send Gift page to show the current user's number of points of the function, we simply add the following program in the index () method of the IndexAction.class.php file://Get the current user's points $money = X (' credit ') Getusercredit ($this->mid), $moneyType = GetConfig (' credit '), $this->assign (' money ', $money [$moneyType]); Add the following line of code to the template for sending the gift: {$money. alias} I currently have: {$money. Credit} and then in the function that sends the gift (UserGiftModel.class.php Sendgift () method) Add the corresponding integral program to deduct the selected gift://deduct the corresponding integral $giftprice = Intval ($giftInfo [' Price ']); $prices = $userNum * $giftPrice; $moneyType = GetConfig (' credit ');//integral Operation $setcredit = X (' credit ');//check if integral is sufficient $usercredit = $setCredit->geTusercredit ($fromUid), if ($userCredit [$moneyType] [' Credit ']< $prices) {return $userCredit [$moneyType] [' Alias ']. ' Insufficient, gift failure ~ ';} $setCredit->setusercredit ($fromUid, array ($moneyType = = $prices),-1); This calls the integral Operation class in the public class library services, which is X (' credit '). Here, the point consumption function has been increased. Increase the notification function first need to increase the gift notification template. Create a folder CN under the language/directory, and then create the notification template file notify.php under the CN folder, with the following code: Array (' title ' = ' = ' {actor} ' gives you a gift ', ' body ' and $img. '
'. $sendback. '
'. $content. '
Go to see 18/32 ',),);? > Add the following procedure after sending the gift successfully://Send notification to the recipient $this->__donotify ($toUser, $sendInfo, $giftInfo, $fromUid, $appId); __donotify () See the specific code for the implementation of the method. This invokes the system notification class in the public class library services, which is X (' Notify '). The notification function has been completed here. The mechanism of sending dynamic sending dynamic function is identical to the mechanism of sending notifications, except for the following two points: notify using/language/cn/feed.php, and use/language/cn/notify.php notification Service dynamically using X (' Notify ') or service (' Notify '), and dynamic use of x (' feed ') or service (' feed ') is not used because the gift application is not dynamic. Add Weibo sharing feature first we need to add a gift template in "Manage background-content-Template management": 19/32 before assembling the notification data, initialize a given object variable://The object name of the gift is used for public giving of Weibo $tousername = NULL; Add the following code to the notification message of the Assembly's public offering to each of the received users://Gift Object name $tousername. = ' @ '. GetUserName ($fid). ' After the notification message is assembled, add the following code to hold the microblog information in SESSION://Open the meager if ($toUserName) {$_session[' Gift_send_weibo '] = UrlEncode (Serialize ( Array (' user ' = $toUserName, ' title ' + $giftInfo [' name '], ' content ' + $data [' content '], ' url ' = = U (' gift/ Index/index ', Array (' uid ' = = $fid, ' type ' =>1, ' Type_data ' =>realityimageurl ($giftInfo [' img '])))));} In the lib/index/indexaction.class.php file, add the following code in the Sendbox () function://To determine whether there is a public gift information, exists, then assign a value to the template, for the meager if (Isset ($_session[' Gift_send_weibo ']) &&!empty ($_session[' Gift_send_weibo ')) {$this->assign (' Tpl_data ', $_session[' Gift_send_weibo ']); unset ($_session[' Gift_send_weibo ');} In the Gift sendbox.html template file that is sent under the tpl/default/index/directory, add the Weibowidget reference (only loaded when the message that sent the microblog exists), as follows: {: W (' Weibo ', Array (' tpl_name ' = ' = ' Gift_send_weibo ', ' button_title ' = ' share ')} To the public to send the microblogging function is complete. Adding an application backend ThinkSNS2.0 to add a management background to your app is simple, directly in the application's action/ Directory, add the AdminAction.class.php file, and then import and inherit the Administratoraction class to complete the Rights management: Note: In the _initialize function, the first thing to do is to execute parent::_initialize () to determine the administrative permission. For more detailed code please see the specific documentation. Then we add the corresponding Management page template, add admin/directory under the tpl/default/directory, then add _header.html, _footer.html, _tab.html, index.html in this directory, Giftlist.html, category.html, edit_gift_tab.html, edit_category_tab.html several template files. Templates are developed in the same way as the foreground templates, and are not duplicated here. Make the Install/uninstall package Add the installation information directory under the app's directory, name AppInfo, and then add the app icon (ico_app.gif, ico_app_large.gif), App profile (info.php) to the directory, Apply the installation file (install.php), the application database file (Install.sql), and the application uninstall file (uninstall.php). Configuration file Contents: ' Gift ',//application brief [required] ' DESCRIPTION ' + ' gift giving ',//managed type [Required] (0: Local application, 1: Remote application) ' Host_type ' + ' 0 ',//front entrance [required] (format: action/ ACT) ' app_entry ' = ' index/index ',//application icon [Required] ' icon_url ' + site_url. '/apps/gift/appinfo/ico_app.gif ',//application icon [Required] ' large_icon_url ' = Site_url. '/apps/gift/appinfo/ico_app_large.gif ',//backstage entrance [optional] ' admin_entry ' = ' admin/index ',//Statistics entry [optional] (format: model/method) 21 /+ ' statistics_entry ' = ' giftstatistics/statistics ', [...]; > Note: One of the site _url is the Web root URL, if you directly use it itself, the program will automatically interpret the absolute URL, there is a benefit is that the site transfer when the information is not required to modify, the program will automatically explain the new URL assigned to it. Of course, you can also use absolute URLs. Installation file Contents: Database operation statements are uniformly placed in the database file Install.sql, install.php function is to execute the file: Executesqlfile ($sql _file), if (!empty ($res)) {//Error echo $res [' Error_code '];echo '
'; Echo $res [' Error_sql '];//clears the imported data include_once (Apps_path. ' /gift/appinfo/uninstall.php '); exit;}? > database File contents: First, write the application three data table add statement, and then add the application system configuration information and micro-blog template INSERT statement, if there is a set of integration rules of the application, plus the integration rules INSERT statement, you can see the log, album and other applications of the database file, the code is as follows: SET foreign_key_checks=0; [...... SQL statements for three data tables and their preset information] #添加ts_system_data数据REPLACE into ' ts_system_data ' (' uid ', ' list ', ' key ', ' value ', ' Mtime ') VALUES (0, ' Gift ', ' credit ', ' s:5: ' score '; ', ' 2010-12-24 11:22:17 '); #模板数据DELETE from ' ts_template ' WHERE ' name ' = ' Gift_send_weibo ' INSERT into ' ts_template ' (' name ', ' Alias ', ' title ', ' Body ', ' lang ', ' type ', ' type2 ', ' is_cache ', ' CTime ') 22/32values (' Gift_send_weibo ', ' gift giving ', ' ', ' I give {user} A gift: ' {title} ' {content} participates in gift-giving {URL} ', ' zh ', ' gift ', ' Weibo ', 0, 1290417734); The SQL files and statements exported by the tool can be used directly here. Uninstall the file content: Delete the app's datasheet, app configuration information, and Weibo templates. If the application also set the integration rules, you also need to delete their integration rules, you can see the log, album and other applications such as uninstall files. Execute ($v);? > The installation and uninstallation package is complete. Login to the background and go to apps---app management--add apps, click the Install app. Then update the system cache to see our gift app in the foreground app list. Debugging to debug our program, there are many ways, here we recommend a few common debugging methods. Use the Dump () method thinkphp to print out the process variables to see if it is the same as the expected results use the thinkphp getlastsql () method to obtain the final SQL statement and print it out with dump () to check if the SQL statement is correct in the conf/ config.php file Add Debug_mode constant and assign to true, that is, thinkphp debug mode open (Note: Need to clean up the cache after the change)
http://www.bkjia.com/PHPjc/477150.html www.bkjia.com true http://www.bkjia.com/PHPjc/477150.html techarticle Core and service, public model, plug-ins, widgets, third-party class library together constitute a big foundation of the system, all other applications are built on it. Terminology Interpretation Core: From the thinkphp framework, ...