0

Whats the right way of giving $_SERVER['DOCUMENT_ROOT'] path.

UPDATED:

Ie) In my app\design\frontend\base\default\template\folder\index.php i need to call other config files which is in document root of magento.

  <?php
    // Show only compile error
    error_reporting(E_COMPILE_ERROR );
    // check if pdo library enabled ? 
    require_once($_SERVER['DOCUMENT_ROOT'] . '/magento/test/ajax_table.class.php');
    $obj = new ajax_table();
    $records = $obj->getRecords();
  ?>
<!DOCTYPE html>
<html>
 <head>
   <script>
        ...
   </script>
 </head>
</html>

var\www\html\magento\test\ajax_table.class.php

require_once($_SERVER['DOCUMENT_ROOT'] . '/magento/test/config.php'); 
class ajax_table {
..
 }

If i include the above:

<?php
// Show only compile error
error_reporting(E_COMPILE_ERROR );
// check if pdo library enabled ? 
require_once('/test/ajax_table.class.php');
$obj = new ajax_table();
$records = $obj->getRecords();
?>

UPDATED:

Also path mismatch here:

\magento\skin\frontend\rwd\default\js\test\script.js

ajax = function (params,action){
$.ajax({
    type: "POST", 
    url: "ajax.php",    //ajax.php is in var\www\html\magento\test\ajax.php
    data : params+"&action="+action,
    dataType: "json",
    success: function(response){
    ...}

I get blank screen with controller error...

Table insertion/ other operation is happening if i keep my index.php in same var\www\html\magento\test folder.

Its path issue.

The file seems to get called when i echo inside it, but functionality is not as expected, which works if i keep index.php too in the root folder, but i want it in design folder

2
  • How you are calling this file in url ` app\design\frontend\base\default\template\folder\index.php `. I think it's wrong folder structure according to magento and magento code not allowed here. Commented Nov 9, 2016 at 8:32
  • where have i specified in url for index.php? im calling index.php from layout Commented Nov 9, 2016 at 10:01

3 Answers 3

2

I think magento in main folder so you can add easily add it like. try this and let me know

 $includePath = Mage::getBaseDir(). "/test/config.php";
    require_once( $includePath);
10
  • @SachinS updated the code... Commented Nov 9, 2016 at 6:48
  • How about the path in url: in .js file?? Commented Nov 9, 2016 at 6:48
  • url: "<?php echo Mage::getBaseDir() ?>ajax.php", if is located with same directory with index.php Commented Nov 9, 2016 at 6:49
  • ajax.php is in magento root folder and index.php is in design template folder Commented Nov 9, 2016 at 6:51
  • 1
    Ok thanks..working...fixed from this : magento.stackexchange.com/questions/3565/… Commented Nov 9, 2016 at 7:52
0

You can call it like this :

require_once __DIR__ . '/test/ajax_table.class.php';
0
$path = Mage::getBaseDir('test/ajax_table.class.php');
require_once ($path);

and in ajax_table.class.php use this

$path = Mage::getBaseDir('test/config.php');
require_once ($path); 
3
  • Invalid dir type requested: test/ajax_table.class.php Commented Nov 9, 2016 at 7:02
  • @SachinS Is 'magento' your root directory and all magento files installed in this folder ? Commented Nov 9, 2016 at 7:09
  • yes magento is the root Commented Nov 9, 2016 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.