Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to set up my program's code
    text
    copied!<p>I'm in the process of creating a new program. It's being created in a way I've never created anything before. The program basically consists of the following:</p> <ul> <li><strong>Index.html</strong> - The interface, just HTML code</li> <li><strong>ActionController.js</strong> - Included by index.html, it contains jquery hooks to interface elements, makes Ajax calls and updates the interface</li> <li><strong>ExampleAction.php</strong> - One of the many 'Action' files that the ActionController calls to using Ajax. It does numerous things depending on the file, but the layout of the files is the same.</li> </ul> <p>The problems I am having with this setup is as follows:</p> <p>1.I wasn't able to accomplish creating a singleton for my database class because using ajax I am forced to create a new database instance in every ExampleAction file. Is this normal behaviour or should it be possible and it's probably something in my code? If it should be possible and it's something in my code I will post it later.</p> <p>If I'm not being clear enough, this is what I tried: - I renamed index.html to index.php (ofcourse). - Included my database singleton at the top of this file. - Made the ajax call to ExampleAction.php. - ExampleAction.php doesn't have access to the database class and I have to include it again and create a new instance.</p> <p>2.When I make the Ajax call I send Parameters through a POST. The general layout of the ExampleAction is as follows:</p> <pre><code>$actionInstance = new ExampleAction(); class ExampleAction { public __construct() { this.GetAction(); } private GetAction() { $action = $_POST['action']; switch ($action) { case "Login": this.Login(); break; } //Login function, etc. here } } </code></pre> <p>Ofcourse my real code contains sanitization and such, the switch statements are longer and it contains a lot more functions</p> <p>What I don't like about this is two things. I don't like that I have to instantiate the object every time I make a call to the file, but I guess that can't be helped.</p> <p>The second thing is that, if I have a lot of functions, my switch becomes huge.</p> <p>All of these problems are making me think I'm going about this all wrong.</p> <p><strong>TL;DR:</strong> I'm looking for the best way to set up a program such as the one I am making. I get the feeling I'm making my code slower (because of the increasing amount of ajax calls) and harder to maintain by the minute (because of the ever-increasing switch statement.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload