我使用的腳本(applications/view/pages/home.php
)由此獲得並顯示另一個腳本的內容其中有一個AJAX請求使用的數據庫連接(我們把它叫做scheduler.php
)。調度程序文件只是一個包含基於從AJAX請求傳遞給它的$ _GET參數動態修改的html的文件。笨 - 用AJAX請求
我的問題是,這個動態內容來自數據庫,並且由於scheduler.php被AJAX調用,所以它不會繼承$this->db->
的能力。
我得到的錯誤:Fatal error: Using $this when not in object context
。
我該如何解決這個問題?我是CodeIgniter和AJAX的新手。謝謝!
編輯:Scheduler.php代碼:
<?php
$shift = $_GET['shift'];
?>
<table>
<tr>
<th><?php echo $d->format('l') . '<br>' . $d->format('F jS'); ?></th>
</tr>
<tr>
<td>
<?php
$this->db->select('id', 'event', 'time');
$query = $this->db->get('myTable', $shift, $shift-5);
foreach ($query->result() as $row) {
echo "<a href='/schedule/{$row['id']}'>{$row['event']} at {$row['time']}</a><br>";
}
</td>
</tr>
</table>
您scheduler.php可能不是一個控制器。 –
你可以添加你的scheduler.php代碼嗎? –
這不是一個控制器,不。它應該是?再次,我是CodeIgniter的新手(我的經驗僅僅基於用戶指南,大約一週的工作)。 – Mephoros