In my index.php file, I firstly require some files and make connection to the database with php..
<?php
// Require every .php file inside "phpClasses" folder
foreach (glob("phpScripts/*.php") as $filename) {
require $filename;
}
// Create the $db object
$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// Connect to the database
$db->connect();
// Instantiate the "language" and "databaseQuery" classes
$lang = new language();
$dbQuery = new databaseQuery();
// Detect if the laguage has changed from the user and apply the new "current language"
if(isset($_GET["change_lang"])) {
$change_lang = $_GET["change_lang"];
$cur_lang = $change_lang;
} else {
$cur_lang = $lang->getCurLang();
}
?>
In the same file, I include ‘home.php’ file to display database content..
<div id="cur_content" class="temp_content" data-tempPos="0">
<?php
include 'pages/home.php';
?>
</div> <!-- #cur_content -->
In the ‘home.php’ file I re-create $dbQuery class and call getText() function like this:
<?php
$dbQuery = new databaseQuery();
?>
<div id="content_home" class="cur_content_inner">
<?php
$text_pos = 'home_inner_1';
$dbQuery->getText($text_pos, $cur_lang);
?>
</div>
‘index.php’ remains without refreshing and user navigates via ajax calls. New content is loaded inside #cur_content div, deleting the previous one.
All works justs fine at the first loading of the page, but when ‘home.php’ is requested again (without index.php refreshing), I get php error because the initial ‘require’ is not happening.
How can I require these files again, after the ajax call?
Sorry, but I am new to this! 😉
Appreciate every help!
Problem solved -> http://codeigniter.com/forums/viewthread/59450/
I used this:
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest") {
foreach (glob("phpScripts/*.php") as $filename) {
require_once $filename;
}
// Create the $db object
$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// Connect to the database
$db->connect();
}
What you will need to do is something like this:
Take this snippet and put it in a separate file, say
includes.phpNow remove it from index.php and just add
includes.phpinto all your navigational pages includinghome.php