Welcome Guest, Not a member yet? Register   Sign In
Use CI functions within linked javascript file
#1

[eluser]Daniel H[/eluser]
Hi

I'm a newbie so please bear with me. I'm using CI and Spry. I'm extremely keen to use the CI db to xml util to generate datasets for use with Spry, but since I'm creating a dataset like this...

Code:
<!--
var dsTags = new Spry.Data.XMLDataSet("<?=base_url();?>system/application/views/datasets/ds_tags.php", "Tags/Tag");
dsTags.setColumnType("AgencyDisciplineID", "number");
//-->

I obviously cannot use dbutil within ds_tags.php. Is there an easy way I can include this functionality within this file?

Thanks!
#2

[eluser]xwero[/eluser]
why don't you link it to a controller instead of directly linking to a view file?

If you have several calls you have to make to the database you can create a controller and a model just for spry.
Code:
class Spry extends Controller
{

  function Spry()
  {
    parent::Controller();
    $this->load->database();
    $this->load->model('Sprymodel','',true);
  }

  function Allnews()
  {
     echo $this->Sprymodel->Allnews();
  }

}
// model
class Sprymodel extends Model
{
  
  function Sprymodel()
  {
    parent::Model();
    $this->load->dbutil();
  }

  function Allnews()
  {
     $query = $this->db->get('news');
     return $this->dbutil->xml_from_result($query);
  }
}

And then you just use the normal CI url structure to import the data you need.
#3

[eluser]Daniel H[/eluser]
That works absolutely perfectly!! Thank you so much for your help.




Theme © iAndrew 2016 - Forum software by © MyBB