将Laravel应用程序连接到Joomla

时间:2020-06-19 02:18:47

标签: php laravel joomla

我正在尝试将Laravel应用程序连接到同一服务器上的Joomla 3实例。我在Laravel中有一个Ajax调用,该调用正在发布到Laravel控制器文件(PHP),但出现错误:

在../ public_html / webapp / app / Http / Controllers / JoomlaController.php:12

中找不到类'App \ Http \ Controllers \ JFactory'

我认为我缺少一些简单的东西。

ajax调用看起来像这样:

$.ajax({
        url: '{{ url() }}/settings/save', 
        type: "POST",
        dataType:'text', 
        data: "test",
        success: function(data) {
                console.log("posted: " + data);
        },
        error: function(){
                console.log("failure posting settings");
        }
 });

我将上面的URL路由到JoomlaController.php,就像这样:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/../../../../' ));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

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


class JoomlaController extends Controller {



public function saveSettings(Request $settings) {

    $user = JFactory::getUser();
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);

    $field = $db->quoteName('value') . ' = ' . $db->quote($settings);
    $condition = $db->quoteName('item_id') . ' = ' . $user->get('id');
    $table = $db->quoteName('nicqb_fields_values');
    $columns = array('field_id','item_id', 'value');
    $values = array('1', $user->get('id'), '\''.$settings.'\'');

        $query
            ->insert($table)
            ->columns($db->quoteName($columns))
            ->values(implode(',', $values));
    }

    $db->setQuery($query);

    $result = $db->execute();

}

}

?>

谢谢。

0 个答案:

没有答案