Re: php - page flow issue...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



sounds like you want to build an ajax site with global config settings
per subpart(=functionality) for each browser-client.

if it got it right your other requirements are;
- you have run-time config/state settings per subpart instance that
other subparts' instances need to access.
- you want to be able to load subparts within subparts on the site,
also with varying configs.

so i'd say you need a $_SESSION['config'] = array (array(....)).

if you need to store your config, put it in a mysql db with
adodb.sf.net, single table, fields: userID (varchar(250)),
sessionStartDate (datetime), [more fields], config (text).
$sql = 'insert into config (userID,config) values
("'.antiSQLinjection($userID).'",
"'.antiSQLinjection(json_encode($SESSION['config'])).'");';
$q=$adoDBconn->execute($sql); if ($q!==false) { echo 'config updated.'
};

don't bother to make a sql datamodel for the config until it's old and
rusted, or you'll waste much time updating it when your app evolves.

anyways, all subparts need a unique name.
and all instances of any subpart also need an (autogenerated via
random-string / start-date-time) ID/name.
an instance is a running copy of a subpart, with it's own $localConfig.

and all variables in a config for a subpart need to get short yet
descriptive, standarized names. without a prefix.
this is to allow "superglobals" to be overriden by "more local config settings".

$_SESSION['config'] = array (
  'subparts' => array (
     'subPart1Name' => array (
        'global' => array ( /* all browser-specific variables for
subPart1Name, "global" level */ ),
  )),
  'instances' => array (
    'subPart1Name_instance1-ID' => array ( /* all overridden settings
for subPart1Name used in subPart1InstanceID */)
  ),
  'currentSiteLayout' => array(
    'topLevel' => array (
      'subPart1Name_instance1-ID' => array(),
      'subPart5Name_instance2-ID' => array(
         'children' => array (
            'subPart8Name_instance1-ID' => array()
         )
      )
     )
   )
);
Because this allows for much flexibility, that also means it can get messy.
Be careful not to put paradoxes in such a config array.
Or sensitive data.

But it does allow for saving all runtime config settings for any
number of apps on a web desktop, with any number of child-apps per
app.

You need a way to load these subparts without loading too much code.
Let's put the "front-end for a subpart" in a script filename &
function-name that can be called polymorphically.
$subpartIncludeFile = HD_ROOT.'php/subpart_'.$subPartName.'.php';
And lets give each such script at least a function named
'loadHTML_subpart_'.$subPartName ($configArray);
This function should return the HTML needed for the subpart given a
possible $configArray, and this function should call CMS-level
functions to query &/ update the $_SESSION['config'] aswell.

And let's make a single script to load a div with a subpart, to be
called from javascript;
/php/loadSubpart.php?name=subPartName&config={array_as_json_urlencoded}
obviously this will include only the relevant $subpartIncludeFile =
HD_ROOT.'php/subpart_'.$subPartName.'.php';

Centralize your CMS/MVC logic in a single (or a few) require_once()
script(s) and require_once() them at the top of index.php (and at the
top of /php/subpart_xyz.php);
/php/myCMSfunctions.php

Your index.php can put out HTML that uses ajax at all times to load
subparts, or it can push all required html for a page out in 1 go.
Afterall, it has access to the (stored) $_SESSION['config'], and can
load and run the subparts like the ajax script /php/loadSubpart.php
would.
The latter is better imo because it saves some overhead.

As for the javascript end, i recommend jquery.com to simplify all ajax handling.
Their docs are quite good too.
You'll at least need to build a javascript function
loadSubpart(divID_string, subpartName_string, configOverride_array).

Best to put all your CMS' js functions in a single js object from the
start, to keep the namespace clean.
For an example of how to set something like that up, have a look at
http://mediabeez.ws/htmlMicroscope-1.3.0/hm.source.js (site may be
offline for hours sometimes, check "htmlmicroscope" via google and use
the googlecode link to get a copy)

If you need the entire config on the js end (security risks!) then use
json_encode to transfer between php and js. JS has no native
json_encode, but there are several good ones for free on json.org

good luck :)

On Sun, Mar 14, 2010 at 5:53 PM, bruce <badouglas@xxxxxxxxx> wrote:
> hi.
>
> got a situation for a potential page that i'm playing with. i'm trying
> to figure out how to implement it, and the best/good approach to this.
> i'm actually considering integrating this kind of process within a cms
> (joomla/mambo/cmsms/etc..) but right now, this is in the initia
> thought stage...
>
> if you have a thought/page that i can lok at that's actually
> implementing this kind of flow.. i'd really like to see it..
>
> so, here goes...
>
> ===============================================
>
> --need to figure out a way to have the user invoke an action on the
> top section of
>  a page, and have that action, trigger an action on a separate part of the page
>
>
> example:
>
> i have a page that looks something like this:
>
>  +---------------------------------------------------------------+
>
>     initial navbar stuff (always shown on the page)
>
>     <form name="foo">
>       stateList (select/option)
>     </form>
>
>
>     +----------------------------------+
>       <form name="cat"> based on the user
>         selected state                             {
>          <tbl name="dog"> based on the user        {  <<<<< based on
> the selected state
>           user state                               {
>                                                    {
>          "cancelBTN"  "submitBTN"
>       </form>
>
>     +----------------------------------+
>
>                                                        (page1)
>  +---------------------------------------------------------------+
>
> i need to have a way to have the user select a "state" from the
>  statelist, and to then have the tbl/section of the site under
>  the "cat" form, generated, based on the selected state.
>
> at the same time, i need a way to have the user select an item
>  from the "dog" tbl, and to have the user select the
>  cancelBTN/submitBTN, with the app then generating the
>  subsequent action/logic. the page below, is a kind of
>  example of what i'm thinking of...
>
>  +---------------------------------------------------------------+
>
>     initial navbar stuff (always shown on the page)
>
>     <form name="foo">
>       stateList (select/option)
>     </form>
>
>
>     +----------------------------------+
>       <form name="cat2"> based on the user
>         selected state, and the cat1.submitBTN
>
>          confirmation section
>                                                              {
>           based on the user selection from page1/cat1        { <<<
> based on the previous
>           cancel/submitBTN                                   {
> cancel/submitBTN
>
>          "cancelBTN"  "submitBTN"
>       </form>
>
>     +----------------------------------+
>
>                                                        (page2)
>  +---------------------------------------------------------------+
>
>
> i can see a couple of ways of accomplishing this...
>
> 1) i can have a page of logic, that is composed of a bunch of
>  logic, that is basically an "if block", that generates/displays
>  the different parts of the page, based on the user actions of
>  the preceding pages/sections (the cancel/submitBTNs). this approach
>  would essentially require the entire page to be regenerated with
>  each BTN selection.
>
>  the logic would generate/invoke the correct page elements based
>  on the user selection/action of the previous page/section.
>
> 2) i could possibly utilize div/frames, to allow the content in
>  the targeted div/frame to be updated/redrawn/regenerated based
>  on the user action/selection of the previous page/section...
>
>  this might be able to be done (not familiar with the
>  underlying processes to know if this is doable/suitable)
>  or even a goof approach..
>
>  would this apaproach still require the entire page to be
>  redrawn? or just the portion that's in the targeted
>  div/frame...
>
> 3) somehow invoke javascript/ajax function/features/logic,
>  to allow the actions/interaction to occur, such that the
>  content in the targeted div/frame is modified, without
>  requiring the rest of the page to be modified...
>
>  i have no idea if this is doable, or what this would mean,
>  or involve, or how to apprach this..
>
>
> or, there might be a different way of accomplishing this
>  that i haven't even thought of...
>
> any example sites/docs/code would be greatly appreciated...
> heck, i'd even be glad to see an actual site/code that
> demonstrates how this can/might/should be implemented!!!
>
>
> thoughts/comments...
>
> thanks
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux