Hello, I've got a website that I initially wrote with PHP and jQuery (with jQuery UI, Bootstrap, TouchPunch, etc). I found I was doing a lot of jQuery related work, coupled with some php for initial loads. It became that I was more or less doing double the code (one for php to do the logic at render time, then jQuery adding the same logic for dynamic Ajax related functionality).
I was looking into Angular, and I think that it will allow me to reduce the jQuery code, and remove much of the PHP loading and really keep the PHP on the backend as opposed to front-end. However, I am running into some difficulties (which as I have found out isn't that surprising).
I am starting with my options page as it has multiple pages and the next step with it was to really make it more dynamic/jQuery oriented (perfect spot for angular controllers). However I have a problem and I am not sure how to handle it.
Basically I have a main file called app.js which creates my base application:
var app = angular.module('davesapp',[]);
This is what is set in the html tag (ng-app="davesapp"). Then I have a second file called: options.js. It defines a second app/module:
var app = angular.module('davesapp-settings',[]);
This file is included in the options.php page in the content section (so it is loaded only on the options page). This file has all my objects/functions related to the options page. Including loading settings via ajax, ($http.get) and saving settings ($http.post) as well as a function for controlling which options setting to show.
This files controllers only work if I include it in the app.js file. Like so:
var app = angular.module('davesapp',['davesapp-settings']);
Now, this works fine on the options.php page however it causes issues with other pages as I don't include the options.js file on other pages (not needed). Is there some way for me to create an array of some sort that based on the page I can tell it what to include/not include? Like for example on the options page have it look the same as above, but on say the archive page have it be:
var app = angular.module('davesapp',['davesapp-archive']);
Also, I am really liking the Angular idea primarily for things like the ng-repeat and the ng-show/hide that I can put right in the raw html (similar to the way the PHP is done) vs doing foreaches / $('div').show()/hide() of jQuery separately. However I kind of feel like maybe adding in Angular might be over complicating things... but with the level of dynamic stuff that this site will have.. I think it will be much cleaner than trying to do it with both PHP and jQuery alone.
Also, not sure if it will make any difference, but I use the Slim Framework with the site so it handles all the routing/templating. The Angular is purely to make sections of the code much cleaner and allow for more dynamic sections without a bunch of jQuery.
Question
firey
Hello, I've got a website that I initially wrote with PHP and jQuery (with jQuery UI, Bootstrap, TouchPunch, etc). I found I was doing a lot of jQuery related work, coupled with some php for initial loads. It became that I was more or less doing double the code (one for php to do the logic at render time, then jQuery adding the same logic for dynamic Ajax related functionality).
I was looking into Angular, and I think that it will allow me to reduce the jQuery code, and remove much of the PHP loading and really keep the PHP on the backend as opposed to front-end. However, I am running into some difficulties (which as I have found out isn't that surprising).
I am starting with my options page as it has multiple pages and the next step with it was to really make it more dynamic/jQuery oriented (perfect spot for angular controllers). However I have a problem and I am not sure how to handle it.
Basically I have a main file called app.js which creates my base application:
This is what is set in the html tag (ng-app="davesapp"). Then I have a second file called: options.js. It defines a second app/module:
This file is included in the options.php page in the content section (so it is loaded only on the options page). This file has all my objects/functions related to the options page. Including loading settings via ajax, ($http.get) and saving settings ($http.post) as well as a function for controlling which options setting to show.
This files controllers only work if I include it in the app.js file. Like so:
Now, this works fine on the options.php page however it causes issues with other pages as I don't include the options.js file on other pages (not needed). Is there some way for me to create an array of some sort that based on the page I can tell it what to include/not include? Like for example on the options page have it look the same as above, but on say the archive page have it be:
Also, I am really liking the Angular idea primarily for things like the ng-repeat and the ng-show/hide that I can put right in the raw html (similar to the way the PHP is done) vs doing foreaches / $('div').show()/hide() of jQuery separately. However I kind of feel like maybe adding in Angular might be over complicating things... but with the level of dynamic stuff that this site will have.. I think it will be much cleaner than trying to do it with both PHP and jQuery alone.
Also, not sure if it will make any difference, but I use the Slim Framework with the site so it handles all the routing/templating. The Angular is purely to make sections of the code much cleaner and allow for more dynamic sections without a bunch of jQuery.
Link to comment
Share on other sites
3 answers to this question
Recommended Posts