Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial phpcms这种需求如何写 难度有点大

phpcms这种需求如何写 难度有点大

Jun 23, 2016 pm 01:41 PM

象下面这段代码是静态的html文件里的写法
如果我把它写在php文件中,怎么改呢

{pc:content action="lists" catid="6" order="id DESC" thumb="" moreinfo=""  return="data" }{loop $data $n $r}<li><a href="{$r['url']}" title="{$r['title']}">{$r['title']}</a></li>{/loop}{/pc}
Copy after login


我试了一下直接放在php文件中是不能解析了,我试图把缓存中的文件复制进来,但一看缓存真是乱七八糟的有很多,多余的代码,有没有写的
干净点的代码呢


回复讨论(解决方案)

{pc:content action="lists" catid="6" order="id DESC" thumb="" moreinfo="" return="data" }
的含义是:
查询内容数据表(lists)
条件为分类号为 6
按 id 降序排列
将结果放到名为 data 的数组中

select * from lists where catid=6 order by id desc
Copy after login
Copy after login

{loop $data $n $r}
  • {$r['title']}

  • {/loop}
    的含义是:对查询得到的数组循环输出
    foeeach($data as $n=>$r) {  echo "<li><a href=\"{$r['url']}\" title=\"{$r['title']}\">{$r['title']}</a></li>":}
    Copy after login
    Copy after login

    {pc:content action="lists" catid="6" order="id DESC" thumb="" moreinfo="" return="data" }
    的含义是:
    查询内容数据表(lists)
    条件为分类号为 6
    按 id 降序排列
    将结果放到名为 data 的数组中

    select * from lists where catid=6 order by id desc
    Copy after login
    Copy after login

    {loop $data $n $r}
  • {$r['title']}

  • {/loop}
    的含义是:对查询得到的数组循环输出
    foeeach($data as $n=>$r) {  echo "<li><a href=\"{$r['url']}\" title=\"{$r['title']}\">{$r['title']}</a></li>":}
    Copy after login
    Copy after login


    lists不是一个表,而是一个方法,参见phpcms手册

    那你就在手册里找答案呗
    我不用 phpcms 所以我在网上找答案  http://bbs.phpcms.cn/thread-287675-1-1.html

    方法1:找到phpcms的模板引擎,单独解析这段字符串
    方法2:手动将模板标签改写成php脚本

    PC标签的编译,可以看下系统类库中的模板引擎phpcms/libs/classes/template_cache.class.php中的pc_tag()方法
    {pc:模块名/操作方式 参数名="参数值"}{/pc}

    像{pc:content action="lists" catid="6" order="id DESC" thumb="" moreinfo=""  return="data" },实际上是调用内容模块的内容列表。
    通过catid确定栏目所属的模型及表名,return则为返回的查询结果的变量名。
    这一步,可以看phpcms/modules/classes/content_tag.class.php。这是pc标签调用content模块时用的类。

    方法1:找到phpcms的模板引擎,单独解析这段字符串
    方法2:手动将模板标签改写成php脚本


    能说说方法吗,如何单独解析,有点晕


    方法1:找到phpcms的模板引擎,单独解析这段字符串
    方法2:手动将模板标签改写成php脚本


    能说说方法吗,如何单独解析,有点晕

    所以我写了方法2...
    不过更好奇为什么要把模板内容转到php中



    方法1:找到phpcms的模板引擎,单独解析这段字符串
    方法2:手动将模板标签改写成php脚本


    能说说方法吗,如何单独解析,有点晕

    所以我写了方法2...
    不过更好奇为什么要把模板内容转到php中
    方法二在哪里呢,最好别太笼统了,象我们这样的菜鸟要具体 的方法,

    菜鸟...都是谦虚且懂礼貌的
    #1已经回答你了

    菜鸟...都是谦虚且懂礼貌的
    #1已经回答你了



    菜鸟...都是谦虚且懂礼貌的
    #1已经回答你了


    你能不能别捣乱啊,不说话你不会死的,相信我

    #1已经回答你了啊,你自己去找lists方法,看用的是哪张表,把表名替换一下不久好了。

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    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)

    Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

    Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

    PHP Logging: Best Practices for PHP Log Analysis PHP Logging: Best Practices for PHP Log Analysis Mar 10, 2025 pm 02:32 PM

    PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

    cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

    The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

    Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

    Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

    12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

    Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

    Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

    Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

    Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

    The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

    See all articles