Home Backend Development PHP Tutorial Single piece mode of discuz X_PHP tutorial

Single piece mode of discuz X_PHP tutorial

Jul 20, 2016 am 11:10 AM
discuz about plug-in article model of Highlight

The article introduces an original article about the single mode of discuz

As long as the file of ">

The code is as follows Copy code
 代码如下 复制代码

$discuz = & discuz_core::instance();
[code language=php]

 

// instance()属于discuz_core类在class_core.php
function &instance() {
static $object;
if(empty($object)) {
  $object = new discuz_core();
}
return $object;
}
[/code]
这里保证单词请求都运用一个discuz_core实例。这里的&写法是为了兼容PHP4的,如果在PHP5中,则可以使用static。
[code language=php]
//这里是单件模式的简单例子。
class PHPig {
private static $v = null;
static function instance() {
  if(self::$v == null) {
   self::$v = new PHPig();
  }
  return self::$v;
}
}
$pig1 = PHPig::instance();
$pig2 = PHPig::instance();
if($pig1 === $pig2) {
echo '同一个对象';
} else {
echo '不是同一个对象';
}
[/code]

$discuz = & discuz_core::instance();
[code language=php]

// instance() belongs to discuz_core class in class_core.php
function &instance() {
static $object;
if(empty($object)) {
$ object = new discuz_core();
}
return $object;
}
[/code]
This ensures that word requests use a discuz_core instance. The & writing method here is for compatibility with PHP4. If it is in PHP5, you can use static.
[code language=php]
//Here is a simple example of the singleton pattern.
class PHPig {
private static $v = null;
static function instance() {
if(self::$v == null) {
self: :$v = new PHPig();
}
return self::$v;
}
}
$pig1 = PHPig::instance();$pig2 = PHPig::instance();
if($pig1 === $pig2) {
echo 'same object';
} else {
echo 'Not the same object';
}
[/code]

http://www.bkjia.com/PHPjc/444705.html
www.bkjia.comtrue
http: //www.bkjia.com/PHPjc/444705.htmlTechArticleThe article introduces an original article about the single mode of discuz X. The PPC highlighting plug-in is too unfriendly. I If you post txt content directly, strange problems will occur. As long as X is present at the beginning of the file...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! Mar 15, 2024 pm 04:13 PM

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

Share three solutions to why Edge browser does not support this plug-in Share three solutions to why Edge browser does not support this plug-in Mar 13, 2024 pm 04:34 PM

When users use the Edge browser, they may add some plug-ins to meet more of their needs. But when adding a plug-in, it shows that this plug-in is not supported. How to solve this problem? Today, the editor will share with you three solutions. Come and try it. Method 1: Try using another browser. Method 2: The Flash Player on the browser may be out of date or missing, causing the plug-in to be unsupported. You can download the latest version from the official website. Method 3: Press the "Ctrl+Shift+Delete" keys at the same time. Click "Clear Data" and reopen the browser.

Detailed explanation of Discuz registration process: allowing you to easily modify personal information Detailed explanation of Discuz registration process: allowing you to easily modify personal information Mar 13, 2024 pm 12:21 PM

"Detailed Explanation of Discuz Registration Process: Allowing you to easily modify personal information, specific code examples are required" Discuz is a powerful community forum program that is widely used in various websites. It provides a wealth of user registration and personal information modification. functions and interfaces. This article will introduce you to Discuz's registration process in detail and provide specific code examples to help you easily customize and modify your personal information. 1. User registration process In Discuz, user registration is one of the important functions of the site. The smoothness of the registration process and

Do Not Disturb Mode Not Working in iPhone: Fix Do Not Disturb Mode Not Working in iPhone: Fix Apr 24, 2024 pm 04:50 PM

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

A must-have for Discuz users! Comprehensive analysis of renaming props! A must-have for Discuz users! Comprehensive analysis of renaming props! Mar 12, 2024 pm 10:15 PM

A must-have for Discuz users! Comprehensive analysis of renaming props! In the Discuz forum, the name change function has always received much attention and demand from users. For some users who need to change their name, name change props can easily modify the user name, and this is also an interesting way of interaction. Let’s take an in-depth look at the renaming props in Discuz, including how to obtain them, how to use them, and solutions to some common problems. 1. Obtain name-changing props in Discuz. Name-changing props are usually purchased through points or the administrator

Solve the problem that Discuz WeChat sharing cannot be displayed Solve the problem that Discuz WeChat sharing cannot be displayed Mar 09, 2024 pm 03:39 PM

Title: To solve the problem that Discuz WeChat shares cannot be displayed, specific code examples are needed. With the development of the mobile Internet, WeChat has become an indispensable part of people's daily lives. In website development, in order to improve user experience and expand website exposure, many websites will integrate WeChat sharing functions, allowing users to easily share website content to Moments or WeChat groups. However, sometimes when using open source forum systems such as Discuz, you will encounter the problem that WeChat shares cannot be displayed, which brings certain difficulties to the user experience.

Discuz background account login exception, how to deal with it? Discuz background account login exception, how to deal with it? Mar 09, 2024 pm 05:51 PM

Title: Discuz background account login exception, how to deal with it? When you use the backend management of the Discuz forum system, you may sometimes encounter abnormal account login. This could be due to a variety of reasons, including a wrong password, account being blocked, network connection issues, etc. When encountering this situation, we need to solve the problem through simple troubleshooting and processing. Check whether the account number and password are correct: First, confirm whether the account number and password you entered are correct. When logging in, make sure the capitalization is correct and the password is

Discuz Editor: Powerful web page editing tool Discuz Editor: Powerful web page editing tool Mar 09, 2024 pm 06:06 PM

Discuz Editor: A powerful web page editing tool that requires specific code examples. With the development of the Internet, website construction and content editing have become more and more important. As a common web page editing tool, Discuz editor plays an important role in website construction. It not only provides a wealth of functions and tools, but also helps users edit and publish content more conveniently. In this article, we will introduce the features and usage of the Discuz editor, and provide some specific code examples to help readers better understand and use

See all articles