joomla component development with Ajax queries

前端 未结 3 2081
悲&欢浪女
悲&欢浪女 2021-01-15 15:26

I have a PHP script used for AJAX queries, but I want them to be able to operate under the umbrella of Joomla\'s (2.5) framework so I can have session id\'s, user id\'s etc

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-15 16:14

    This is absolutely possible by way of the Joomla Platform. The example I'll give you below is actually for J1.5, but is easily adaptable to J2.5 with some adjustment to the included files.

    1. Create a joomla platform file to include as shown below:
    2. Include that file in your script
    3. Use the now-available Joomla environment for your functions.

    Another strong recommendation is to implement a ReSTful API instead of your custom scripts. It's outrageously simple using Luracast Restler. I had it up and running in about 10 minutes, then added the Joomla Framework as shown below, and had an extremely flexible Joomla based API using AJAX calls for my site in under an hour! Best spent development time in years, as far as I'm concerned.

    yourscript.php

    require_once('joomla_platform.php');
    /* Get some of the available Joomla stuff */
    $config = new JConfig(); 
    $db = &JFactory::getDBO(); 
    $user =& JFactory::getUser();
    if($user->gid <25) {
        die ("YOU CANT BE HERE");
    }
    echo "
    ".print_r($config,true)."
    ";

    joomla_platform.php

    
    

提交回复
热议问题