Php 您如何创建一条消息;有一个更新可用;为了Joomla分机?
Joomla在登录后端后检查是否有可用的更新。如果是,您可以在单击“查看更新”时看到概览。但我想显示一条关于我开发的扩展的更新的类似消息(“有可用的更新”)。我试过一些方法,但到目前为止还没有成功。有什么建议吗?这是我为我的组件遵循的代码。您可以在views->tmpl->default.php文件中使用相同的方法Php 您如何创建一条消息;有一个更新可用;为了Joomla分机?,php,joomla,message,Php,Joomla,Message,Joomla在登录后端后检查是否有可用的更新。如果是,您可以在单击“查看更新”时看到概览。但我想显示一条关于我开发的扩展的更新的类似消息(“有可用的更新”)。我试过一些方法,但到目前为止还没有成功。有什么建议吗?这是我为我的组件遵循的代码。您可以在views->tmpl->default.php文件中使用相同的方法 <?php $user = JFactory::getUser(); ?> <div class="UpdatesPage" style="margin-top
<?php $user = JFactory::getUser(); ?>
<div class="UpdatesPage" style="margin-top: 8px">
<?php
$xml = JFactory::getXML(JPATH_ADMINISTRATOR .'/components/com_mycomponent/manifest.xml');//Path to your existing manifest file.
$existingversion = (string)$xml->version;
$url = 'http://example.com/downloads/mycomponent.xml';
//$url is path to your xml file which stores the latest version.
$ch = curl_init($url);//Execute curl and get the xml data available in my server
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// 400 means not found, 200 means found.
curl_close($ch);
if($retcode == 200){
$xml2 = JFactory::getXML($url,true);
$latestversion = $xml2->update->version;
} else {
$latestversion = "";
}
?>
<h2>Version Update</h2>
<?php
if ( version_compare($latestversion, $existingversion) > 0) {
echo "<span style='color:#AFA;text-align:center;'>The version installed is ".$existingversion."</span><br />";
echo "<span style='color:red;text-align:center;'>The latest version is ".$latestversion."</span><br />";
} else {
echo "<span style='color:green;text-align:center;'>You have the Latest version</span>";
}
?>
</div>
版本
$url='1http://example.com/downloads/mycomponent.xml';
//$url是存储最新版本的xml文件的路径。
$ch=curl\u init($url)//执行curl并获取我的服务器中可用的xml数据
curl_setopt($ch,CURLOPT_NOBODY,true);
curl_exec($ch);
$retcode=curl\u getinfo($ch,CURLINFO\u HTTP\u代码);
//400表示未找到,200表示已找到。
卷曲关闭($ch);
如果($retcode==200){
$xml2=JFactory::getXML($url,true);
$latestversion=$xml2->update->version;
}否则{
$latestversion=“”;
}
?>
版本更新
包装组件
包裹
0
1.1.1
http://www.example.com
https://example.com/index.php?option=com_mycomponent
稳定的
http://www.example.com
测试
也许可以检查具有您描述的功能的Akeeba备份的代码。仍然存在一个问题:我的更新xml和更新文件位于带有https的站点上,当我在本地工作时,这似乎没有问题。那么脚本就可以正常工作了。当我在使用https的实时站点上尝试该脚本时,我得到一个错误,即无法读取来自updatesite的XML文件。另一方面,Joomla在更新列表中确实显示了正确的更新。这个问题可以在脚本中解决吗?@Franky在$url='1'中http://example.com/downloads/mycomponent.xml';代码>您使用的是http还是https?正如您所说的,这是https,所以您需要将此变量更改为https。所以你的url应该是$url=https://example.com/downloads/mycomponent.xml';代码>是的,我从一开始就在url https中,在$retcode=curl\u getinfo($ch,CURLINFO\u HTTP\u code)中;之后我也切换到了https。但是没有任何区别,XML没有被加载。奇怪…@Franky我很惊讶为什么它不起作用,因为即使我使用https,我的组件也能正常工作。
<?xml version="1.0" encoding="utf-8"?>
<updates>
<update>
<name><![CDATA[My Component]]></name>
<description><![CDATA[Download Component]]></description>
<element>pkg_mycomponent</element>
<type>package</type>
<client>0</client>
<version>1.1.1</version>
<infourl title="example.com">http://www.example.com</infourl>
<downloads>
<downloadurl type="full" format="zip">https://example.com/index.php?option=com_mycomponent</downloadurl>
</downloads>
<tags>
<tag>stable</tag>
</tags>
<maintainer><![CDATA[Amit Ray]]></maintainer>
<maintainerurl>http://www.example.com</maintainerurl>
<section>Testing</section>
<targetplatform name="joomla" version="3"/>
</update>
</updates>