Jump to content
Larry Ullman's Book Forums

Modularising A Website And Php Redux


Recommended Posts

Hi,

 

I have been experimenting with the modularised approach as per chapter 2 and really like the concept.  However, one of my sites has lots of PHP redux in the admin scripts which update a database and upload lots of selected files. 

 

Can one use PHP redux and the modularised approach, wherein all accesses are channelled through a controller/index.php script, together?

 

The problem that I am 'admiring' is that when a script calls itself (via PHP redux), the modularised approach would seem to require that that call be channelled through the controlling script, index.php. 

 

Can this be done or are the two approaches incompatible?

 

Thanks in anticipation for any thoughts/guidance.

 

Cheers from Oz.

Link to comment
Share on other sites

Hi Hartley-san,

 

Let me try and clarify... On page 57 Larry makes the comment that index.php is the "only page that should ever be loaded in the Web browser".  Index.php then includes configuration and header stuff and then includes a page (at a time) from the /modules/ folder which does the actual work.  Let's say that the module which is included uses php redux, e.g., after say displaying a form, the module calls itself to process that form.  When it calls itself it doesn't go through the index.php control structure and thus is missing all the config and header logic which is part of the index.php structure.

 

So maybe the modularistaion structure is incompatible with an included module which then calls itself to process form data via php redux.

 

Again, thanks for any thoughts/guidance on this matter.

 

Cheers from Oz.

Link to comment
Share on other sites

Hmmm... I'm still not sure if I understand or not, but my thought process is that the module pattern will work fine with what you want to accomplish.

 

For example, you may have an index.php file like the following:

<?php
  
  include('../config.php');
  include(MYSQL);
  include(HEADER);
  
  include(FORM_MODULE);
  
  include(FOOTER);
 
And in the FORM_MODULE script, you might have something like the following:
<?php
  
  if (isset($_POST['hidden_val'])) {
    // Process form.
  }
  
  // Display form here with sticky values, as necessary.
  // Also, the action attribute for the form should be the index.php script.

 

By doing that, you are able to achieve your module pattern as well as have a single page (index.php) drive the entire experience.

Is that what you were talking about?

Link to comment
Share on other sites

Yes, I see what you are getting at...

 

At the moment the action is not set at all so the module just calls itself - I will try it with the action set to index.php and the appropriate GET parameter value.

 

Thanks for you thoughts.

Link to comment
Share on other sites

You should definitely be posting the form, not using the GET method.

Also, you can leave the action attribute empty, but I've heard that the default form behavior in that case can be a bit inconsistent in old browsers, which is why I always explicitly set it (usually by using some constant in my config file).

Link to comment
Share on other sites

 Share

×
×
  • Create New...