Joomla Configuration.php如何使用函数更新类变量并分配它们

时间:2017-01-09 16:38:51

标签: php oop joomla

我需要帮助您使用此类中的函数更新$host$user$password$db变量。

所以基本上在函数内部做一些工作然后更新变量的值并让它返回输出。

我可以更新$this->user例如并回显输出。但是我无法用它更新类变量$user

<?php
class JConfig {
	public $offline = '0';
	public $offline_message = 'This site is down for maintenance.<br />Please check back again soon.';
	public $display_offline_message = '1';
	public $offline_image = '';
	public $sitename = '';
	public $editor = 'tinymce';
	public $captcha = '0';
	public $list_limit = '20';
	public $access = '1';
	public $debug = '0';
	public $debug_lang = '0';
	public $dbtype = 'mysqli';
  public $host = '';
  public $user = '';
	public $password = '';
	public $db = '';
  public $dbprefix = 'i1jud_';
	public $live_site = '';
	public $secret = '';
	public $gzip = '0';
	public $error_reporting = 'default';
	public $helpurl = 'https://help.joomla.org/proxy/index.php?keyref=Help{major}{minor}:{keyref}';
	public $ftp_host = '';
	public $ftp_port = '';
	public $ftp_user = '';
	public $ftp_pass = '';
	public $ftp_root = '';
	public $ftp_enable = '0';
	public $offset = 'UTC';
	public $mailonline = '1';
	public $mailer = 'mail';
	public $mailfrom = '';
	public $fromname = '';
	public $sendmail = '/usr/sbin/sendmail';
	public $smtpauth = '0';
	public $smtpuser = '';
	public $smtppass = '';
	public $smtphost = 'localhost';
	public $smtpsecure = 'none';
	public $smtpport = '25';
	public $caching = '0';
	public $cache_handler = 'file';
	public $cachetime = '15';
	public $cache_platformprefix = '0';
	public $MetaDesc = '';
	public $MetaKeys = '';
	public $MetaTitle = '1';
	public $MetaAuthor = '1';
	public $MetaVersion = '0';
	public $robots = '';
	public $sef = '1';
	public $sef_rewrite = '0';
	public $sef_suffix = '0';
	public $unicodeslugs = '0';
	public $feed_limit = '10';
	public $feed_email = 'none';
  public $log_path = '';
	public $tmp_path = '';
	public $lifetime = '15';
	public $session_handler = 'database';
	
}

<?php
class updates
{
    public $user;
    function __construct(){
     $this->user = "user";
    }

    function username()
    {
         return $this->user = "new_user";
    }
    
     
}

$updates = new updates();
echo $updates->username();

?>

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

您提到的configuration.php中的变量是指数据库名称,数据库用户和数据库密码,而不是joomla用户。这与JUser对象无关,除非您正在移动您的站点,否则您永远不会想要更改它们。也就是说,这是整个网站的配置。

为什么不首先通过更改用户来解释您要完成的任务。例如,您是否尝试编写CLI脚本来执行安装或将站点从一个数据库移动到另一个数据库?

答案 2 :(得分:0)

创建三个方法username,password,db。

使用构造函数,使用方法的结果更新变量。的工作原理。