I’m developing a web app using Kohana PHP framework and I got stuck. I set a PHP variable in my Controller to use it in a View. I would like to update this variable in the View continuously without refreshing the page. What I’d like to do is show a chart in real time using data from an SQL database where the curves’ data is stored in this PHP variable. How can I do this? Is it possible to update this variable directly in the View (using my function in the Model)?
Share
You can create an AJAX request with Javascript to your application without reloading the page. What happens is that the request is made to your controller/action, there you can query your database and you can pass back whatever your like. The AJAX request can retrieve the returning data and do something with it (in our case, replace some content with the new content).
You have to include this Javascript code on your page. In this example I use jQuery to make the AJAX request:
In your Kohana controller you have something like this:
Your Html of your view will be like this (according to the example):