php Joomla 3,2的CLI脚本示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Joomla 3,2的CLI脚本示例相关的知识,希望对你有一定的参考价值。

<?php
/**
 * @package		Joomla.Cli
 *
 * @copyright  Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 * 
 * Joomla 3.2 example CLI script
 * Written by: Rene Kreijveld, email [at] renekreijveld.nl
 * 05-feb-2014
 * Put this script in the /cli folder in the root of your Joomla 3.2 website
 * Execute by php <path_to_your_joomla_root>/cli/clidemo_3.2.php
*/

/**
 * A command line cron job to trash expired cache data.
 */

// Initialize Joomla framework
const _JEXEC = 1;

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
	require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
	define('JPATH_BASE', dirname(__DIR__));
	require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

/**
 * @package  Joomla.CLI
 * @since    3.0
 */
class Clidemo extends JApplicationCli
{
	/**
	 * Entry point for the script
	 *
	 * @return  void
	 *
	 * @since   3.0
	 */
	public function doExecute()
	{
		// Database connector
		$db = JFactory::getDbo();

		$this->out('Setting query');
		// Set SQL query
		$query = "SELECT COUNT(*) from #__users";
		// Execute query
		$db->setQuery($query);
		// Get result
		$number_of_users = $db->loadResult();

		$this->out('Query done');
		// Output result
		$this->out("We found $number_of_users users.");
	}
}

// Instantiate the application object, passing the class name to JCli::getInstance
// and use chaining to execute the application.
JApplicationCli::getInstance('Clidemo')->execute();

以上是关于php Joomla 3,2的CLI脚本示例的主要内容,如果未能解决你的问题,请参考以下文章

PHP 中的 Joomla 独立脚本 - 握手

在另一个 php 脚本中使用 joomla 会计

Joomla 2.5 从外部脚本获取用户数据

需要Joomla 2.5 自定义组件Router.php 说明

joomla 自定义表单注销用户

Joomla组件开发(3.3.3版)