Site with backslash on localhost

Asked

Viewed 470 times

0

I downloaded the site from the server and put it to run on localhost. However, it is not calling the files correctly. First, it calls "http://localhost" and then the folder path, with backslash.

inserir a descrição da imagem aqui

There is a rule set to call all files:

<?php
define("MY_BASE_DIR", 'C:');
define("SITE_PATH", __DIR__ . '/');
define("SITE_VIRTUAL_DIR", str_replace($_SERVER["DOCUMENT_ROOT"], "", SITE_PATH));
define("ENGINE_PATH", SITE_PATH.'includes/fw/'); // caminho pro FW
define("CMS_ENGINE_PATH", SITE_PATH.'includes/cms/cms.php');

I tried to change that rule, but to no avail.

This backslash setting is some chunk in the code files you have either modified or is my local server configuration (I’m using Wampserver)?

----------------------------- UPDATE ------------------------------

This is the file that gives way to the files:

public function Setup()
{
    parent::Setup();

    if (\Browser::Obsolet())
    {
        $this->context->UpdateYourBrowser();
    }

    if(!defined("ADMIN_DIR")){
        define("ADMIN_DIR", dirname($_SERVER["SCRIPT_NAME"]) . "/");
        define("ADMIN_URL", DOMAIN . ADMIN_DIR );
    }

    if(!defined("ADMIN_PATH"))
    {
        throw new \Exception("Para acessar um módulo do backend você precisa esta no diretorio do admin/");
    }

    // configura a sessao do usuario
    $this->context->set("USER.SESSION", $this->context->get("USER.SESSION") . ADMIN_PATH . "_ADMIN");

    // configura o template do ADMIN
    // checa se o usuario especificou algum caminho para o template do ADMIN
    $templatePath = $this->context->get("CMS.ADMIN.TEMPLATE_PATH");
    if(!$templatePath){
        $templatePath = ADMIN_PATH;
    }
    $this->context->setTemplatePath($templatePath); //diretorio raiz de templates?
    $this->context->setTemplate($this->context->get('CMS.ADMIN.TEMPLATE')); // seta o template configurado no config.php

    // checa se o usuario especificou algum caminho para o template do ADMIN
    $templateUrl = $this->context->get("CMS.ADMIN.TEMPLATE_URL");
    if(!$templateUrl){
        $templateUrl = ADMIN_DIR; // URI do admin: http://localhost/admin/
    }
    if(!defined("TEMPLATE_URL"))
        define("TEMPLATE_URL", $templateUrl . $this->context->TemplateDir() . $this->context->getTemplate() . "/");
}

@Rafaelphp The files are being called through the TEMPLATE_URL:

<link rel="stylesheet" href="<?php echo TEMPLATE_URL ?>static/css/bootstrap.min.css" rel="stylesheet">

I’m still trying to get him to call it straight, but to no avail.

  • Did that work on linux? What happens is that the substitution doesn’t happen.

  • The DIR takes the current file directory, soon will have the full Windows path, take a look at the $_SERVER array, it contains some alternatives to set SITE_PATH. Just give a var_dump in it. I think $_SERVER['REQUEST_URI'] should help you.

  • you have how to post what you have in the source code ex: <link rel="stylesheet" type="text/css" href="<?php echo $obj->script_path" />

  • I updated my question, please see if possible.

1 answer

1

I believe that part of the problem is in this section:

define("SITE_PATH", __DIR__ . '/');
define("SITE_VIRTUAL_DIR", str_replace($_SERVER["DOCUMENT_ROOT"], "", SITE_PATH));

The name "SITE_VIRTUAL_DIR" suggests that it must be the virtual path, but is mixing with the physical path.

To better understand, physical path is something like this C:/www/site/;
And virtual path is something like http://site/foo/

In the codes posted it is not possible to state where the error really is because the final result is mounted in this section

 if(!defined("TEMPLATE_URL"))
        define("TEMPLATE_URL", $templateUrl . $this->context->TemplateDir() . $this->context->getTemplate() . "/");
}

A practical way to find the problem is to create breakpoints in the most obvious locations and analyze the data.

Suggestions for breakpoints:

Shortly after define("SITE_VIRTUAL_DIR", str_replace($_SERVER["DOCUMENT_ROOT"], "", SITE_PATH));, add echo SITE_VIRTUAL_DIR; exit;

If you’re not wrong, go to another logical point and break another point.
Obviously, disable the previous breakpoint to continue the execution.

Right after that line

define("TEMPLATE_URL", $templateUrl . $this->context->TemplateDir() . $this->context->getTemplate() . "/");

Add that

echo TEMPLATE_URL.PHP_EOL.'<br>';
echo $templateUrl.PHP_EOL.'<br>';
echo $this->context->TemplateDir().PHP_EOL.'<br>';
echo $this->context->getTemplate().PHP_EOL.'<br>';
exit;

I’m pretty sure that’s where you’ll get a better idea of the origin of the problem. 'Cause you’ll know exactly where the part you’re riding wrong comes from.

But anyway, I can’t guarantee anything. They’re just logical observations. Just try to understand the logic of breakpoints to debug the code and then learn how to fix your codes.

Another thing more obvious is, try to know if there is no documentation of this system or if you cannot consult the author of it. A simple query can be better than licking code.






Related Pegunta (SO-en)https://stackoverflow.com/questions/38543229/site-with-wrong-call-on-localhost

Browser other questions tagged

You are not signed in. Login or sign up in order to post.