Php Joomla-更新用户表中的名称
我在本地机器上安装了Joomla 3 我编辑了默认注册页面以隐藏名称字段,其中我没有使用全名作为字段,而是将其分为名字、中间名和姓氏 幸运的是,保存的记录是成功的,我也可以更新它们 问题是,当管理员开始管理用户列表时,没有继续的链接。这意味着带有链接的字段,即名称字段(完整字段)为空 我的目标是,注册后,我可以用连接的名字、中间名和姓氏填写该字段 我怎么能在Joomla 3中做到这一点Php Joomla-更新用户表中的名称,php,joomla,Php,Joomla,我在本地机器上安装了Joomla 3 我编辑了默认注册页面以隐藏名称字段,其中我没有使用全名作为字段,而是将其分为名字、中间名和姓氏 幸运的是,保存的记录是成功的,我也可以更新它们 问题是,当管理员开始管理用户列表时,没有继续的链接。这意味着带有链接的字段,即名称字段(完整字段)为空 我的目标是,注册后,我可以用连接的名字、中间名和姓氏填写该字段 我怎么能在Joomla 3中做到这一点 谢谢。您可以使用。这个链接将向您展示如何使用example.php(我相信,Joomla安装中包含了这个)。您
谢谢。您可以使用。这个链接将向您展示如何使用
example.php
(我相信,Joomla安装中包含了这个)。您可能最感兴趣的是函数onUserBeforeSave
,如果您在Joomla保存输入之前对其进行操作,甚至可能不需要更改模块。您需要开发一个自定义用户插件来正确管理此功能。此外,如果您要编写插件,您应该将整个用例合并到插件中。下面是您的主插件文件外观的快速草稿:
<?php
defined('_JEXEC') or die;
class plgUserCustom extends JPlugin
{
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
}
// Called while Joomla is loading the form for the view
// This is where you would remove or alter fields
// and load your custom xml form definition for the
// first, middle and last names
public function onContentPrepareForm($form, $data)
{
// Confirm valid JForm object or exit
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
// If the active view isn't listed in array exit as plugin not needed
//
// com_users.registration = front end registration form
// com_users.profile = front end edit profile form
// com_users.user = back end administrators form
if (!in_array($form->getName(), array('com_users.registration', 'com_users.profile', 'com_users.user'))) {
return true;
}
// The core JForm object for the view will be loaded
// manipulate the fields any way you like
// In below example, the name field will be removed
// from the users registration, profile and admin user manager view
if (in_array($form->getName(), array('com_users.registration', 'com.users.profile', 'com_users.user'))) {
$form->removeField('name');
// Now add the form xml path for your custom name fields
// In this example the plugin has a forms directory
JForm::addFormPath(dirname(__FILE__) . '/forms');
$form->loadFile("custom", false);
}
return true;
}
// This is where Joomla loads any existing data into the form field
// and where you would take the standard name field and separate
// into first, middle and last name values and attach to data object.
// The data object property names must match the field name in your
// xml form definition file.
public function onContentPrepareData($context, $data) {
// Verify you are in the correct form before manipulating data
if (!in_array($context, array('com_users.profile','com_users.user', 'com_users.registration'))) {
return true;
}
// explode core name field into parts, attach to core data object
// as first, middle and last name and unset name data.
// CAUTION: You should implement check to verify middle name entered
// or not by verifying if parts array length is 2 or 3
$parts = explode(" ", $data->name);
$data->first_name = $parts[0];
$data->middle_name = $parts[1];
$data->last_name = $parts[2];
unset($data->name);
}
return true;
}
// This method fires before Joomla save the user data and is where
// you should combine the first, middle and last names into one name
// and attach to data object and remove references to first, middle and
// last names.
public function onUserBeforeSave($user, $isNew, $data) {
// Manicure data before save, implode first, middle and last name
// into one field and add to data object, unset first, middle and last
// name from data object
$data->name = implode(" ", array($data->first_name, $data->middle_name, $data->last_name));
unset($data->first_name);
unset($data->middle_name);
unset($data->last_name);
return true;
}
public function onUserAfterSave($data, $isNew, $result, $error)
{
return true;
}
public function onUserAfterDelete($user, $succes, $msg)
{
return true;
}
public function onUserLogin($user, $options)
{
return true;
}
public function onUserLogout($credentials, $options) {
return true;
}
}
\u subject->setError('JERROR\u NOT\u A\u FORM');
返回false;
}
//检查我们正在操作一个有效的表单。
//如果活动视图未在数组中列出,则退出为不需要的插件
//
//com_users.registration=前端注册表
//com_users.profile=前端编辑配置文件表单
//com_users.user=后端管理员表单
如果(!in_array($form->getName(),array('com_users.registration','com_users.profile','com_users.user')){
返回true;
}
//将加载视图的核心JForm对象
//按您喜欢的方式操纵字段
//在下面的示例中,名称字段将被删除
//从用户注册、配置文件和管理员用户管理器视图
if(在数组($form->getName(),数组('com\u users.registration'、'com.users.profile'、'com\u users.user'))中){
$form->removeField('name');
//现在为自定义名称字段添加表单xml路径
//在本例中,插件有一个表单目录
JForm::addFormPath(dirname(_文件)'/forms');
$form->loadFile(“自定义”,false);
}
返回true;
}
//这就是Joomla将任何现有数据加载到表单字段的地方
//您将在其中使用标准名称字段并将
//转换为名字、中间名和姓氏值,并附加到数据对象。
//数据对象属性名称必须与数据库中的字段名称匹配
//xml表单定义文件。
公共函数onContentPrepareData($context,$data){
//在操作数据之前,请验证您的格式是否正确
if(!in_array($context,array('com_users.profile','com_users.user','com_users.registration')){
返回true;
}
//将core name字段分解为多个部分,附着到core数据对象
//作为名字、中间名和姓氏以及未设置的姓名数据。
//注意:您应该执行检查以验证输入的中间名称
//或者不通过验证零件数组长度是2还是3
$parts=分解(“,$data->name);
$data->first_name=$parts[0];
$data->middle_name=$parts[1];
$data->last_name=$parts[2];
取消设置($data->name);
}
返回true;
}
//此方法在Joomla保存用户数据之前激发,在何处
//你应该把名字、中间名和姓氏组合成一个名字
//和附加到数据对象,并删除对第一个、中间和
//姓。
公共函数onUserBeforeSave($user、$isNew、$data){
//保存前的指甲数据,内爆名字、中间名和姓氏
//放入一个字段并添加到数据对象,取消设置第一个、中间和最后一个字段
//来自数据对象的名称
$data->name=内爆(“,数组($data->first_name,$data->middle_name,$data->last_name));
未设置($data->first\u name);
取消设置($data->中间名称);
未设置($data->last_name);
返回true;
}
onUserAfterSave的公共函数($data、$isNew、$result、$error)
{
返回true;
}
公共函数onUserAfterDelete($user、$success、$msg)
{
返回true;
}
公用函数onUserLogin($user,$options)
{
返回true;
}
公共函数onUserLogout($credentials,$options){
返回true;
}
}
我添加了编写插件的链接,以帮助您创建和打包安装ZIP以安装插件。我还附加了一个用于创建xml表单定义的链接
祝你好运
正确的方法是