1

My app works fine, but I'm not sure if it's considered "bad practice" with what I'm doing for a particular knockout.js form.

I'm using CakePHP as the backend and knockout.js for a form on one of my views. On this view, the JavaScript file for the Knockout.js form containing the MVVM goodies is included. So, this knockout form accesses the JS script, and one of the functions involves this JS script sending a request out to a different PHP file. Right now this file is just in the root directory of my folder (not in the app directory), and since it's only interacting with the JavasScript directly and not CakePHP I'm wondering if this is a no-no. I guess you could think of it as this PHP file is interacting with the Knockout "system" and not the CakePHP "system".

I made this file a while back to do some calculations and it just seems easier to leave it this way considering I don't need a view or anything displayed from it. JSON format data is sent to it, and it sends modified data back to JavaScript in JSON format. Basically this php file only interacts with JavaScript and never with the CakePHP structure.

1 Answer 1

1

If it doesn't have any relationship with Cake models/controllers/... or anything. I don't see a problem with it being outside of MVC. It can only make it faster, not having to go through the routing and dispatching of a framework.

However on the other hand, if it doesn't do anything with data on the server, why do you need the server anyway? Can't you port the logic to the client-side?

Sign up to request clarification or add additional context in comments.

2 Comments

It's primarily done server because I use PHP DOM and I have a lot of code written that I don't want to re-write (and figure out for that matter) in Javascript/jQuery. I suppose it's more secure too since unless my server is hacked, they can't see the code.
If it's code that doesn't need to be kept secure (e.g. no sensitive data) then I would consider redoing it in JS. Just for the matter of speeding up your application (not waiting for an AJAX call to finish)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.