CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Getting Path to Files in an Extension?
Pages: [1]

Author Topic: Getting Path to Files in an Extension?  (Read 1141 times)

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Getting Path to Files in an Extension?
June 11, 2015, 08:30:08 am
I'm trying to use QZ-Print to RAW print with my extension. I'm having trouble getting my extension to find the file properly. What is the best approach to load files within the extension directory onto my webpage?

For example the directory of  my extension is: /drupal/civicrm/checkin/Checkin/

However, if I point to a file in that directory it is NOT found.

Here is the current code (as a crmScript js file) I am using to embed:

Code: [Select]
deployQZ();
function deployQZ() {
    path = document.location.pathname;
    //alert (path);
    var attributes = {id: "qz", code: 'qz.PrintApplet.class',
        archive: '/drupal/civicrm/checkin/Checkin/qz-print/qz-print.jar', width: 1, height: 1};
    var parameters = {jnlp_href: 'qz-print_jnlp.jnlp',
        cache_option: 'plugin', disable_logging: 'false',
        initial_focus: 'false'};
    if (deployJava.versionCheck("1.7+") == true) {
    }
    else if (deployJava.versionCheck("1.6+") == true) {
        delete parameters['jnlp_href'];
    }
    deployJava.runApplet(attributes, parameters, '1.5');
}

Within my root extension directory I have a qz-print directory with the files in it. The file is not loaded...

Thanks!
« Last Edit: June 11, 2015, 11:33:15 am by lee.gooding »

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Getting Path to Files in an Extension?
June 15, 2015, 01:35:20 pm
Paths like "/drupal/civicrm/foo" are not usually mapped to files; rather, they map to PHP code (ie an XML "route" and a "controller" class). In both cases, the construction of the URL will vary depending on the system, so it's best to use a helper function to consruct the URL. (Example: Drupal+Civi supports clean-URLs, but WP+Civi do not. Extensions support configurable basedirs.)

The way to link to something depends on whether you intend to access a PHP controller or a static file:

 * To reference to a PHP route/controller (from PHP), use CRM_Utils_System::url('civicrm/foo').

 * To reference to a PHP route/controller (from Javascript), use CRM.url('civicrm/foo').

 * To reference to a static file (from PHP), use CRM_Core_Resources::singleton()->getUrl($ext,$file).

 * To reference to a static file (from Javascript), you'll need to run getUrl() in PHP and then export it to JS. For example, in v4.6, you might say:

Code: [Select]
// PHP
function myext_civicrm_pageRun(...) {
   ...
   $res = CRM_Core_Resources::singleton();
   $res->addVars('myext', array(
     'baseUrl' => $res->getUrl('org.example.myext'),
   ));
   ...
}

// Javascript
alert('The URL is' + CRM.vars.myext.baseUrl);

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: Getting Path to Files in an Extension?
June 22, 2015, 12:00:49 pm
This is SUPER helpful. Thanks!

I added this to the WIKI Cookbook as it will probably be helpful for others.
« Last Edit: June 22, 2015, 12:09:27 pm by lee.gooding »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Getting Path to Files in an Extension?

This forum was archived on 2017-11-26.