The singleton class isn't the part that makes it work, and including
global vars will not allows those variables to save data accross
requests or sessions. A global var is just like a local variable in
witango.
When php deals with scope, it deals with scope within a single
request. A global var is one that is available anywhere in the
request, where there may be other variables, that are only available
within a class or within a function.
In order to have data stored in variables, like in custom or domain
scope in php, is to use some type of data caching mechanism. There
are many out there, but this is not built into php. We use a
mechanism that is built into the Zend PHP Platform, and wrap it into
a special singleton class. It works beautifully, and is faster than
anything I have seen, and highly configurable.
If you don't use Zend PHP, then you have to find another class out
there, and there are many, to do the same thing.
Here is a quick example of how we use this type of dynamic caching.
Here are 2 functions, within our application level singleton class,
that stores a group of sections for binder-usa.com.
private function setSections() {
global $global_app;
$myconn = $this->getConnector();
$query = "select * from tblBinderBereich where enabled = 1";
$res = $global_app->getResultSetFromConn($myconn,$query);
return serialize($res);
}
/**
* Returns assoc array of binder sections.
*
* @return array
*/
public function getSections(){
$res = output_cache_fetch
("binder_app_sections","self::setSections()",$this->default_ttl);
return unserialize($res);
}
In php, if I want access to the sections, I just call the getSections
() method from my app class, something like this:
$this_sections = $app_class->getSections();
The getSections method runs the output_cache_fetch() method with 3
parameters. The first parameter, is just a KEY for the data you are
fetching. So you can store as many different items as you wish, of
any data type, you just give each its own key. The second parameter,
is what method to run, to initialize the cache, if the cache data is
not stored. This happens, the very first time you run getSections(),
or after time out. The last parameter, is time to live. How long do
you want this cache to be stored, before clearing.
So the first time you hit it, it runs the setSections() method, which
actually grabs the data from the database, and puts it into cache.
The subsequent times, the db is not touched, it just returns the
cached data. And for each piece of data, you can use a global default
timeout you have set, or tune to use a special timeout, if you want
that data to refresh more often.
A beautiful part of this technique, is you can cache any type of data
or object. The php serialize function allows you to store and
retrieve any type of data instantly. This particular method stores a
results set type of array.
It is these types of well documented features that are part of Zend
PHP and not just PHP that made me choose Zend. There are many more.
Like cluster management, and dynamic caching. Performance is incredible.
--
Robert Garcia
President - BigHead Technology
VP Application Development - eventpix.com
13653 West Park Dr
Magalia, Ca 95954
ph: 530.645.4040 x222 fax: 530.645.4040
[EMAIL PROTECTED] - [EMAIL PROTECTED]
http://bighead.net/ - http://eventpix.com/
On May 4, 2007, at 2:31 PM, Ben Johansen wrote:
You can do this through what is called a "PHP SINGLETON CLASS"
or you can simply create a php file that is included in each php
file that contains the global vars you want to treat as domain scope.
Ben
On May 4, 2007, at 1:59 PM, Dan Stein wrote:
I there an equivalent in PHP to witango custom or domain scopes
variables?
If so how do you declare and access them.
Have to do this project in PHP since pages have to load in
Contribute 3.
--
Dan Stein
FileMaker 7 Certified Developer
Digital Software Solutions
799 Evergreen Circle
Telford PA 18969
Land: 215-799-0192
Cell: 610-256-2843
FMP, WiTango, EDI,SQL 2000, MySQL, PHP
[EMAIL PROTECTED]
www.dss-db.com
"It's very hard to grow, because it's difficult to let go of
models of
ourselves in which we've invested so heavily."
______________________________________________________________________
__
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
______________________________________________________________________
__
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf