0

I have inherited someone else's PHP code & am totally clueless about the language.

I want to add Babel from CDN into my page header right after React & ReactDOM local files are loaded, however, before the app javascript files load up.

Here is the relevant chunk where the files are arranged at: protected -> controllers -> appcontroller.php

public function includeStyles() {
     $baseUrl = Yii::app()->baseUrl;
     $styles = Yii::app()->getClientScript();
     $styles->registerCssFile($baseUrl . '/css/DA_TemSelect.css?' . $this->version);
     $styles->registerCssFile($baseUrl . '/css/styles.css?' . $this->version);
}
public function includeScripts() {
     $baseUrl = Yii::app()->baseUrl;
     $scripts = Yii::app()->getClientScript();
     $scripts->registerScriptFile($baseUrl . '/js/libraries/jquery-ajax.js');
     $scripts->registerScriptFile($baseUrl . '/js/libraries/react.js');
     $scripts->registerScriptFile($baseUrl . '/js/libraries/react-dom.js');

Here is where I want the CDN Babel js file to load, i.e. right after React, however, before the following js files.

$scripts->registerScriptFile($baseUrl . '/js/aphrodite/models/Element.js?'. $this->version);

I should mention, I tried this link but to no avail.

I appear to be using Yii version 1.1.13 (as per the CHANGELOG).

Thanks,

Kayote
  • 14,579
  • 25
  • 85
  • 144
  • Soo... You know where you want it, you know what the line should look like, what's the problem? – Mike Cluck Jan 11 '16 at 23:55
  • @MikeC the problem is how to add the CDN. All of those are '$baseURl'. I tried `$scripts->registerScriptFile($baseUrl . '//cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js');` it doesnt work. Clearly I need to add a variable directing towards the CDN, instead of the `baseURL` – Kayote Jan 12 '16 at 00:03
  • 2
    So why are you prefixing it with `$baseUrl` if you don't want to start it with `$baseUrl`? It doesn't make a sense at all. Just simply pass full CDN URL as a string without any variables. – David Ferenczy Rogožan Jan 12 '16 at 01:12
  • BTW you should think about the code you're writing. Don't just copy&paste what others wrote before. Sorry but this is really absurd question. – David Ferenczy Rogožan Jan 12 '16 at 01:15
  • @DawidFerenczy That actually did the trick. Thank you. Regarding absurd question, we all need help. Maybe you needed some as well to get to where you are now. I have upvoted the comment that answers the question for others. Thanks again. – Kayote Jan 12 '16 at 08:23
  • Sorry, I didn't mean it offensive. It just didn't make a sense to me. It was like Q: "I baked a chocolate cake, but it contains chocolate which I don't like chocolate. What can I do?" A: "Don't put the chocolate there." ;) Anyway I'm pleased you fixed it. Don't be afraid to ask a question next time, maybe just think more first. But it's true we all started somehow :) – David Ferenczy Rogožan Jan 12 '16 at 14:04

0 Answers0