首页 理论 架构 工程 文档 白皮书 著作 研究 案例 下载 博客 关于 开始使用 →

第257章 Smarty Template|Smarty 模板

第257章 Smarty Template|Smarty 模板

257.1 提出背景

在前面的ICAI工程体系中,已经完成了从机器认知对象到行为执行层的逐步建立:

Object Model → Scene Model → Cognitive Model → Behavior Model → Action → Device Model → Device Engine

但是,一个完整的ICAI软件系统不仅需要后台认知对象、模型和引擎,还需要一个能够向操作者展示系统当前认知状态、运行状态和执行结果的表现层。

在PHP MVC工程中,Smarty Template|Smarty模板承担的正是这一职责。

Smarty不是认知引擎,也不是认知模型,更不是行为决策模块。

它属于:

Presentation Layer|表现层

其主要任务是把Controller提供的数据转换成用户能够观察和操作的页面。

因此,ICAI中的Smarty模板应当严格位于:

Cognitive System → Controller → Smarty Template → HTML Interface

这一位置。


257.2 Smarty Template 的定义

Smarty Template|Smarty模板是基于PHP MVC架构建立的页面表现模板,用于接收Controller传递的数据,并将ICAI运行状态、对象信息、场景信息、认知结果、行为状态、设备状态等结构化数据表现为HTML页面。

可以定义:

HTMLt=F(T,Dt)HTML_t=F(T,D_t)

其中:

  • HTMLtHTML_t:当前生成的HTML页面;
  • TT:Smarty Template;
  • DtD_t:Controller在时间 tt 提供的数据。

因此:

Template+Data→ViewTemplate+Data\rightarrow View

Smarty模板本身不负责产生认知。

它只是负责:

把已经形成的认知数据表现出来。


257.3 Smarty Template 与 MVC

ICAI采用MVC结构后,可以形成:

Model
↓
Controller
↓
Smarty Template
↓
HTML
↓
User

其中:

Model|模型

负责数据和系统对象。

例如:

Object Model
Scene Model
Cognitive Model
Behavior Model
Device Model

Controller|控制器

负责接收请求、调用系统模块、组织数据。

例如:

ObjectController
SceneController
CognitiveController
BehaviorController
DeviceController

Smarty Template|模板

负责页面表现。

例如:

object.tpl
scene.tpl
cognition.tpl
behavior.tpl
device.tpl

因此:

MVC=Model+Controller+ViewMVC=Model+Controller+View

而:

View=SmartyTemplateView=SmartyTemplate

在ICAI工程中,Smarty主要承担View层职责。


257.4 Smarty不是认知层

这一点必须明确。

Smarty模板不能直接承担:

对象识别
关系推理
状态计算
认知匹配
行为决策
设备控制

这些工作应该由ICAI的认知引擎和业务引擎完成。

正确结构:

Real-Time Data
↓
Object Engine
↓
Scene Engine
↓
Cognitive Engine
↓
Behavior Engine
↓
Device Engine
↓
Controller
↓
Smarty
↓
HTML

错误结构则是:

Smarty
↓
Cognition
↓
Decision
↓
Device

因此Smarty必须保持表现层边界。


257.5 Smarty的数据输入

Controller向Smarty提供的是结构化数据。

例如:

$smarty->assign('object', $object);
$smarty->assign('scene', $scene);
$smarty->assign('cognition', $cognition);
$smarty->assign('behavior', $behavior);
$smarty->assign('device', $device);

Smarty模板只负责读取这些数据。

例如:

<h2>{$object.name}</h2>

<p>状态:{$object.state}</p>

<p>位置:{$object.position}</p>

这里:

Controller
↓
object
↓
Smarty
↓
HTML

Smarty并没有重新建立Object Model。

它只是表现Object Model已经计算出的结果。


257.6 Cognitive Model 的模板表现

在ICAI系统中,Cognitive Model是核心运行模型之一。

因此可以建立:

Cognitive Model
├── Goal
├── Scene
├── Objects
├── Relations
├── States
├── Cognition
├── Methods
└── Actions

Controller将其传递给Smarty:

$smarty->assign(
    'cognitive_model',
    $cognitiveModel
);

模板负责表现:

当前目标
↓
当前场景
↓
当前对象
↓
当前状态
↓
当前认知
↓
当前方法
↓
当前行为
↓
当前动作

这样操作者可以直接看到机器当前的认知结构。


257.7 Scene Model 的页面表现

Scene Model是动态场景的结构化表示。

因此可以建立:

Scene
├── Objects
├── Relations
├── States
├── Environment
├── Space
├── Time
└── Goal

Smarty可以将其表现为页面:

<h2>Scene</h2>

<div>
    <strong>Scene ID:</strong>
    {$scene.id}
</div>

<div>
    <strong>Scene Type:</strong>
    {$scene.type}
</div>

<h3>Objects</h3>

{foreach $scene.objects as $object}
    <div>
        {$object.name}
        -
        {$object.state}
    </div>
{/foreach}

这样,系统当前场景中的对象、状态和关系可以被实时观察。


257.8 Behavior Model 的页面表现

Behavior Model描述机器当前正在进行的目标导向行为。

因此Smarty可以表现:

Goal
↓
Behavior
↓
Current State
↓
Method
↓
Current Action
↓
Execution Result

例如:

<h2>Behavior</h2>

<p>目标:{$behavior.goal}</p>

<p>行为:{$behavior.name}</p>

<p>状态:{$behavior.state}</p>

<p>当前动作:{$behavior.current_action}</p>

<p>结果:{$behavior.result}</p>

这里模板只显示结果。

行为逻辑仍然由:

Behavior Model + Behavior Engine

完成。


257.9 Device Model 的页面表现

设备层同样可以通过Smarty表现。

例如:

Device
├── Identity
├── Type
├── Capability
├── State
├── Parameters
├── Constraints
└── Feedback

Smarty:

<h2>Device</h2>

<p>设备:{$device.name}</p>

<p>类型:{$device.type}</p>

<p>状态:{$device.state}</p>

<h3>Capabilities</h3>

{foreach $device.capabilities as $capability}
    <div>{$capability}</div>
{/foreach}

这样可以观察:

当前设备是什么、能够做什么、当前是否可用以及正在执行什么。


257.10 动态数据显示

ICAI是动态认知系统,因此Smarty所显示的数据也不是固定数据。

例如:

D(t0)→D(t1)→D(t2)D(t_0)\rightarrow D(t_1)\rightarrow D(t_2)

页面数据也随系统状态变化:

Object State
Idle
↓
Approaching
↓
Contacting
↓
Grasping
↓
Holding

Controller每次请求获得当前模型:

Current Object Model
↓
Current Scene Model
↓
Current Cognitive Model
↓
Current Behavior Model
↓
Current Device Model

然后:

Controller
↓
Smarty
↓
Current View

因此Smarty成为机器认知运行状态的一个可视化表现出口


257.11 Smarty与实时认知状态

传统网页往往表现静态业务数据。

ICAI中的Smarty则主要表现:

Dynamic Cognitive State|动态认知状态

例如页面可以同时显示:

Current Goal
Current Scene
Current Object
Current State
Current Relation
Current Behavior
Current Action
Current Device
Current Feedback

形成一个完整的认知运行界面:

World State
↓
Object State
↓
Scene State
↓
Cognitive State
↓
Behavior State
↓
Action State
↓
Device State

操作者可以通过页面看到整个认知链当前运行到什么位置。


257.12 Smarty中的循环与条件

Smarty允许使用基本的条件和循环结构。

例如:

{if $device.state == 'Running'}
    <span>设备运行中</span>
{else}
    <span>设备未运行</span>
{/if}

以及:

{foreach $scene.objects as $object}
    <div>
        {$object.id}
        {$object.name}
        {$object.state}
    </div>
{/foreach}

这些只是表现层条件

必须注意:

Template Condition
≠
Cognitive Rule

例如:

{if $object.state == 'grasping'}

只是根据已有状态选择页面显示内容。

它不能替代:

State Engine
Cognition Engine
Behavior Engine

中的认知规则。


257.13 Controller → Smarty 数据链

ICAI MVC系统可以建立标准的数据传递流程:

User Request
↓
Controller
↓
Engine
↓
Model
↓
Controller
↓
Smarty
↓
HTML

例如:

public function cognition()
{
    $model = $this->cognitiveEngine->getCurrentModel();

    $this->smarty->assign(
        'cognitive_model',
        $model
    );

    $this->smarty->display(
        'cognition.tpl'
    );
}

其职责非常清晰:

Controller
负责组织数据

Engine
负责运行认知

Model
负责保存结构

Smarty
负责表现

HTML
负责用户界面

257.14 Smarty Template 的目录结构

ICAI可以建立独立的模板目录:

templates/
│
├── layout/
│   ├── header.tpl
│   ├── footer.tpl
│   └── navigation.tpl
│
├── object/
│   ├── index.tpl
│   └── detail.tpl
│
├── scene/
│   ├── index.tpl
│   └── detail.tpl
│
├── cognition/
│   ├── index.tpl
│   └── detail.tpl
│
├── behavior/
│   ├── index.tpl
│   └── detail.tpl
│
└── device/
    ├── index.tpl
    └── detail.tpl

这样可以使不同认知层拥有独立的表现页面。


257.15 Smarty在ICAI中的工程位置

最终,Smarty在整个ICAI系统中的位置可以明确为:

                    ICAI
                     │
        ┌────────────┴────────────┐
        │                         │
   Cognitive System          MVC System
        │                         │
        ↓                         ↓
Object / Scene / Cognition   Controller
        ↓                         ↓
Behavior / Action / Device  Smarty Template
        │                         ↓
        ↓                        HTML
Physical Execution               ↓
        │                       User
        ↓
Feedback
        ↓
Cognitive Update

也就是说,Smarty并不改变ICAI认知结构。

它把认知结构呈现出来


257.16 Smarty Template 与认知系统解耦

ICAI工程需要保持:

CognitiveLogic≠PresentationLogicCognitiveLogic\neq PresentationLogic

其中:

  • Cognitive Logic:认知逻辑;
  • Presentation Logic:表现逻辑。

例如:

Cognitive Engine

可以输出:

array(
    'object' => $object,
    'scene' => $scene,
    'state' => $state,
    'behavior' => $behavior
);

未来即使不用Smarty,而改成其他表现形式:

HTML
API
JSON
Desktop UI
Mobile UI

认知引擎仍然可以保持不变。

因此:

Cognition→DataCognition\rightarrow Data

而:

Data→PresentationData\rightarrow Presentation

两者通过Controller连接。


257.17 Smarty Template 与后续API工程

本章建立的表现层结构,也为后续API与JSON工程提供基础。

同一个Cognitive Model可以:

Cognitive Model
       ↓
   Controller
    ↙      ↘
Smarty      API
 ↓           ↓
HTML        JSON

因此:

Smarty不是ICAI认知系统的核心逻辑层,而是认知数据的人机表现接口。

这一结构使ICAI可以同时拥有:

  • Web管理界面;
  • 认知监控界面;
  • 行为运行界面;
  • 设备运行界面;
  • API数据接口。

而底层认知模型保持统一。


257.18 本章核心模型

Smarty Template在ICAI中的核心模型可以归纳为:

Viewt=F(Controllert,Modelt,Template)View_t=F(Controller_t,Model_t,Template)

完整MVC认知表现流程:

Object Model
↓
Scene Model
↓
Cognitive Model
↓
Behavior Model
↓
Device Model
↓
Controller
↓
Smarty Template
↓
HTML
↓
Human

而机器内部的执行闭环仍然独立运行:

Cognition
↓
Behavior
↓
Action
↓
Device Engine
↓
Device
↓
World
↓
Feedback
↓
Re-Cognition

两条链通过Controller和系统状态数据形成连接。


257.19 本章总结

Smarty Template|Smarty模板在ICAI中的核心定位是:

机器认知结构的人机表现层。

它不负责对象认知、不负责场景构建、不负责行为决策、不负责设备执行。

它负责将:

Object Model → Scene Model → Cognitive Model → Behavior Model → Device Model

这些运行结果,通过Controller传递到页面。

因此形成:

Model→Controller→Smarty→ViewModel\rightarrow Controller\rightarrow Smarty\rightarrow View

而ICAI完整系统形成:

World→Data→Object→Scene→Cognition→Behavior→Action→Device→World→FeedbackWorld \rightarrow Data \rightarrow Object \rightarrow Scene \rightarrow Cognition \rightarrow Behavior \rightarrow Action \rightarrow Device \rightarrow World \rightarrow Feedback

同时:

CognitiveState→Controller→Smarty→HumanObservationCognitiveState \rightarrow Controller \rightarrow Smarty \rightarrow HumanObservation

由此,ICAI不仅具备机器内部认知运行结构,也具备了机器认知状态的人机可观察界面

这为下一阶段的MVC认知系统进一步建立 Controller、Engine、Model、Smarty 四者之间的完整运行关系奠定了工程基础。

Leave a Reply

Your email address will not be published. Required fields are marked *