Error Include PHP Codeigniter

Asked

Viewed 253 times

2

I’m having a question, how do I correctly include in php codeigniter

follows below the script...when I remove the scripts in php works correctly.

<?php include('includes/header.inc.php'); ?>

<body>
<div id="header" class="container">
    <?php include('includes/navigation.inc.php'); ?>
</div>
<div id="banner-wrapper2">
    <div id="banner" class="container">
        <div class="boxD">
            <h3>Quem somos</h3>

        </p>
        </div>
    </div>
</div>

<?php include('includes/footer.inc.php'); ?>

Already with include, gives the error below:

PHP Error was encountered Severity: Warning

Message: include(includes/header.inc.php): failed to open stream: No such file or directory

Filename: pages/quemsomos.php

Line Number: 1

Backtrace:

File: /home/site.com.br/application/views/frontend/pages/quemsomos.php Line: 1 Function: _error_handler

File: /home/site.com.br/application/views/frontend/pages/quemsomos.php Line: 1 Function: include

File: /home/buscadefornecedores.com.br/application/Libraries/Template.php Line: 29 Function: view

File: /home/site.com.br/application/controllers/Pages.php Line: 23 Function: load

File: /home/site.com.br/public/index.php Line: 315 Function: require_once

this is the Routes.php file is on the web in the directory: /application/config/Routes.php

$route['/includes/'] = 'includes/header.inc'; $route['/includes/'] = 'includes/navigation.inc'; $route['/includes/'] = 'includes/footer.inc';

includes in folder: /application/includes/

in the public folder I have only the Assets folder and index.php

If anyone can help me with that question...

Thank you

2 answers

1

Hello! For security reasons and the very scope of what the Codeigniter framework sees, you cannot use other files external to the project to include in your views. In other words, you’re trying to include /home/buscadefornecedores.com.br/application/libraries/Template.php in /home/site.com.br/application/views/frontend/pages/quemsomos.php. These are different projects. Such reference is not possible.

But you could reference code snippets from one view to another, provided of the same project, as follows, for example:

// Nesse caso, dirname(__FILE__) retorna o diretório das suas ../application/views
<?php require_once(dirname(__FILE__).'/../includes/header.php'); ?>

For this example, you would need to have a directory /includes with its code snippets just below /application/views. No need to configure Routes for this.

0

The correct thing would be for you to use the concept of partial view:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <?php $this->load->view('meta'); ?>
    </head>
    <body>
        <div id="wrapper">
            <?php $this->load->view('header'); ?>

            <div id="content">
                <?php echo $content; ?>
            </div>

            <?php $this->load->view('footer'); ?>
        </div>
    </body>
</html>

Where you load other views into one.

Browser other questions tagged

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