I am working in Codeigniter. I have a view, book.php, with a js file, frontend_book.js, running behind it containing a function to sync the calendar.
Snippet from frontend_book.js
googleSync: function() {
provider_id= $('#select-provider').val();
getUrl = GlobalVariables.baseUrl + 'google/sync/' + provider_id;
jQuery.get(getUrl,provider_id, console.log('Google sync successful'),'json');
}
I would like to run this function independent of the view in a cron job using a php function in my google.php controller, that does something like this:
public function syncallproviders() {
//get the array of providers:
$this->load->model('providers_model');
$providers = $this->providers_model->get_available_providers();
//for each providers as provider run the js googleSync
foreach ($providers['id'] as $provider) {
//Run googleSync where #select-provider is $provider
}
}
That I can then run in a cron job with
php /mypath/index.php "google" syncallproviders
How do I integrate this?
This is my best guess at putting the two together:
<?php
//get the array of providers:
$this->load->model('providers_model');
$providers = $this->providers_model->get_available_providers();
//for each providers as provider run google sync
foreach ($providers as $provider) { ?>
<script type="text/javascript">
var getUrl=<?php echo $this->config->base_url().'/google/sync/'.$provider['id']; ?>,
var provider_id =<?php echo $provider['id']; ?>,
jQuery.get(getUrl,provider_id, console.log('Google sync successful'),'json'),
</script>
<?php }
Does this look right? Now how can I make this run from a command line? What can take the place of a browser if I run it from command line?