phproberto / joomla-entity

Joomla! 的实体类

v2.0.0 2019-12-09 09:13 UTC

README

因为开发 Joomla 扩展应该既有趣又简单。

快速入门

让我们用一个快速的例子来说明。这是在 Joomla 中通过 ID 加载文章的实际方法

Load an article

其中 $article 是一个 stdClass 对象。您可以访问其属性,但它实际上是一个虚构的东西,一个端点。

使用文章实体,您可以这样做

Load an article

在这里,$article 是一个文章实体。一个向开发者公开其逻辑和资源的对象。

您可以使用该文章实体完成一些很酷的事情

// Use article as entity
echo $article->get('title');

// Use params transparently
if ($article->param('show_title', '1') === '1')
{
	echo $article->get('title');
}

// Check if article is featured
if ($article->isFeatured())
{
	// Do something
}

// Check if article has an intro image
if ($article->hasIntroImage())
{
	$image = $article->getIntroImage();
	echo '<img src="' . JUri::root(true) . '/' . $image['url'] . '" />';
}

// Check article state
if ($article->isPublished())
{
	echo 'Article published!';
}

// Retrieve article category
echo $article->category()->get('title');

// You can modify article properties
$article->set('title', 'My modified title');

// And save it
try	
{
	$article->save();
}
catch (\RuntimeException $e)
{
	echo 'There was an error saving article: ' . $e->getMessage();
}

查看完整文档以获取其他示例。

安装

前往 发布部分,并遵循最新版本中的 如何安装/升级 指示。

文档

文档发布在 https://phproberto.github.io/joomla-entity/

要求

  • PHP 7.1+
  • Joomla! CMS v3.9+

版权 & 许可证

此库采用 GNU LESSER GENERAL PUBLIC LICENSE 许可。

版权(C)2017-2019 Roberto Segura López - 版权所有。