2013-02-20 14 views
0

我是Joomla的新手,想要了解Joomla! API的作品。未定義的索引:用戶名[...]在線上的 joomla user authentication.php 012

我有這樣一段代碼在一個連接到另一個Joomla網站呼叫APITEST

外部文件基本上,我已創建了一個具有用戶名的用戶:demo和密碼demo12。我想用JApplication類的login()方法。

<?php 
define('_JEXEC', 1); 
define('DS', DIRECTORY_SEPARATOR); 
define('JPATH_BASE', dirname(__FILE__).DS."../apitest/"); 

require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php'); 
require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php'); 
require_once(JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php'); 

$user = JFactory::getApplication('site'); 

$credential = array('demo', 'demo12'); 
$remember = array(true); 

print_r($user->login($credential, $remember)); 

?> 

但是它給了我這個錯誤消息:

Notice: Undefined index: username in C:\xampp\htdocs\apitest\libraries\joomla\user\authentication.php on line 321 

Notice: Undefined index: username in C:\xampp\htdocs\apitest\libraries\joomla\user\authentication.php on line 326 

Notice: Undefined index: password in C:\xampp\htdocs\apitest\libraries\joomla\user\authentication.php on line 331 

我希望得到的結果返回True。我該怎麼做?謝謝。

+0

顯示authentication.php'的'代碼。 – 2013-02-20 10:56:44

回答

1

Joomla正在關聯數組中尋找用戶名和密碼,而不是數字鍵控數組,這就是你所擁有的。

更改爲:

$credential = array('username' => 'demo', 'password' => 'demo12'); 
+0

謝謝!他們應該把它寫在他們的文檔中。行1或320上的 – Vicheanak 2013-02-20 11:02:27

+0

添加$ index = NULL; – Shushant 2013-02-20 11:21:42