Of course. Let's break down arcurl in the context of a DedeCMS (织梦内容管理系统) SQL query.
What is arcurl?
In DedeCMS, arcurl is not a real column name in the main dede_archives table. Instead, it's a virtual field or a SQL function alias that you use within a SQL query to dynamically generate the full URL of an article.
Its primary purpose is to save you from having to manually construct the URL path using other fields like id, typeid, and typedir.
How arcurl Works: The Magic Function
When you use arcurl in a SELECT statement, DedeCMS's database driver (specifically, the custom dedesql.class.php) intercepts this. It recognizes arcurl as a special keyword and replaces it with the necessary PHP logic to build the URL.
The generated URL is typically constructed using the following logic:
- Get the Category Path: It retrieves the
typedirfield from thedede_arctypetable for the article'stypeid. - Apply URL Rewriting Rules: It checks the system's URL rewriting settings (e.g., in
dede/sys_config.phpor the admin panel) to see if the URL should be in a "static" format (like/a/2025/10/01/123.html) or a "dynamic" format (like/plus/view.php?aid=123). - Format the Date: It uses the
pubdatefromdede_archivesto create the year/month/day directory structure (e.g.,/2025/10/01/). - Combine and Return: It combines the category path, date path, and the article's
IDto produce the final, complete URL.
How to Use arcurl in a SQL Query
You use it just like any other column name in a SELECT statement.
Basic Example
Let's say you want to get the ID, title, and the full URL for the 10 most recently published articles.
SELECT
id,
arcurl
FROM
`dede_archives`
ORDER BY
pubdate DESC
LIMIT 10;
When you execute this query through DedeCMS's database layer (e.g., in a PHP file using dsql or dedesql), the arcurl column in the result set will contain the fully formed URLs.
Advanced Example with JOIN
Often, you need information from the category table as well. In this case, you must perform a JOIN and ensure your query logic is correct.
Important Note: When you JOIN the dede_arctype table, the arcurl function might lose its context if not handled correctly by the DedeSQL class. A more robust approach is to select the necessary fields and then construct the URL yourself, or rely on the DedeSQL class's ability to resolve arcurl even in a join.
Here is a query that gets the article title, its category name, and its URL, joining both the archives and arctype tables.
SELECT
a.id,
a.title,
t.typename,
arcurl AS article_url
FROM
`dede_archives` AS a
LEFT JOIN
`dede_arctype` AS t ON a.typeid = t.id
WHERE
a.arcrank > -1 -- Optional: to filter out unapproved articles
ORDER BY
a.pubdate DESC
LIMIT 20;
The Manual Way (Constructing the URL Yourself)
Understanding how arcurl works helps you write queries that are compatible with other tools or if you need to bypass the DedeCMS SQL layer. You can construct the URL manually using the GetArcUrl function in PHP, but if you need to do it purely in SQL, it's very complex and not recommended. The standard practice is to select the required fields and build the URL in your PHP code after fetching the results.
For example, in a PHP file:
<?php
require_once(dirname(__FILE__)."/include/common.inc.php");
$dsql = new DedeSql(false);
$query = "SELECT id, title, typeid, pubdate FROM dede_archives ORDER BY pubdate DESC LIMIT 10";
$dsql->SetQuery($query);
$dsql->Execute();
while($row = $dsql->GetArray())
{
// The magic happens here. DedeSQL automatically resolves 'arcurl'
// if you were to SELECT it. But manually, you can use the global function.
$arcUrl = GetArcUrl($row['id'], $row['typeid'], $row['pubdate'], $row['title'], false);
echo "ID: " . $row['id'] . "<br>";
echo "Title: " . $row['title'] . "<br>";
echo "URL: " . $arcUrl . "<br><hr>";
}
?>
Summary
| Feature | Description |
|---|---|
What is arcurl? |
A virtual field/alias for SQL queries in DedeCMS to get an article's full URL. |
| How does it work? | The DedeSQL PHP class intercepts arcurl in a SELECT statement and dynamically generates the URL. |
| When to use it? | In any SELECT query where you need the article's URL without having to build it manually in PHP afterward. |
| Can I use it with JOIN? | Yes, but it relies on the DedeSQL class to correctly resolve the context. It's generally supported. |
| Alternative? | Select id, typeid, pubdate, etc., and use the PHP GetArcUrl() function to build the URL in your code. |
