elgg添加网页方法

php系统添加hello world网页:

1.安装elgg。

2.创建文件start.php(路径为服务器根目录),内容为:

<?php

elgg_register_event_handler('init', 'system', 'hello_world_init');

function hello_world_init() {

}
这段代码是告诉elgg,它应该在系统初始化时,调用 hello_world_init方法。

3.注册网页处理器:这步的任务是实现在用户请求网址https://elgg.example.com/hello时,处理相关业务。

更新start.php为:

<?php

elgg_register_event_handler('init', 'system', 'hello_world_init');

function hello_world_init() {
    elgg_register_page_handler('hello', 'hello_world_page_handler');
}

function hello_world_page_handler() {
    echo elgg_view_resource('hello');
}
注:当用户访问 https://elgg.example.com/hello/*时, elgg_register_page_handler()告诉elgg调用方法 hello_world_page_handler(),该方法渲染view视图为 resources/hello

4.创建php网页,路径为views/default/resources/hello.php,内容为:

<?php

$params = array(
    'title' => 'Hello world!',
    'content' => 'My first page!',
    'filter' => '',
);

$body = elgg_view_layout('content', $params);

echo elgg_view_page('Hello', $body);
该页向 elgg_view_layout()方法传递titile,content,filter等网站页面的基本信息参数。

elgg_view_page()作为显示页面,检测所有控制信息,并完整展现整个网页。

5.此时,即实现了新建网页功能。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值