|
Posted by Bruno B B Magalhγes on 04/13/05 02:07
Well,
I have a framework class witch loads and stores all classes in it.
I canΒ΄t post the all code, but some I cam:
Loading a core class like a database class:
------------------------------------------------------------------------
-----------
function loadcore(&$handler, $class_name = '')
{
if($class_name != '')
{
if(is_object($this->_crs->$class_name))
{
$handler =& $this->_crs->$class_name;
return true;
}
elseif(file_exists($this->core_dir.$class_name.$this-
>core_sfx.$this->php_sfx))
{
require_once($this->core_dir.$class_name.$this->core_sfx.$this-
>php_sfx);
if(class_exists($class_name))
{
$handler = new $class_name(&$this);
$this->_crs->$class_name =& $handler;
return true;
}
else
{
$handler = false;
return false;
}
}
else
{
$handler = false;
return false;
}
}
else
{
$handler = false;
return false;
}
}
------------------------------------------------------------------------
-----------
Loading a module class:
------------------------------------------------------------------------
-----------
function loadmodule($module_name = 'default_module', $module_method =
'default_method', $method_vars = null)
{
if($module_name != '')
{
if(is_object($this->_mdl->$module_name))
{
if(method_exists($this->_mdl->$module_name, $module_method))
{
$this->_mdl->$module_name->$module_method($method_vars);
return true;
}
}
elseif(file_exists($this->module_dir.$module_name.$this-
>module_sfx.$this->php_sfx))
{
require_once($this->module_dir.$module_name.$this-
>module_sfx.$this->php_sfx);
if(class_exists($module_name))
{
$this->_mdl->$module_name = new $module_name(&$this);
if(method_exists($this->_mdl->$module_name, $module_method))
{
$this->_mdl->$module_name->$module_method($method_vars);
return true;
}
return true;
}
else
{
return $this->_mdl->$module_name = false;
return false;
}
}
else
{
return $this->_mdl->$module_name = false;
return false;
}
}
else
{
return $this->_mdl->$module_name = false;
return false;
}
}
------------------------------------------------------------------------
-----------
I hope it will help you out.
Best Regards,
Bruno B B Magalhaes
On Apr 12, 2005, at 11:09 AM, Jason Barnett wrote:
> php@electroteque.org wrote:
>> Hi there, I have been testing a possible solution to reduce the
>> ammount of
>> interface calling scriptsto my class files. Currently each class has
>> a calling script. I am
>
> For PHP5 you can try __autoload(). It provides for you a last-chance /
> just in time loading of a class file. The main drawback of using this
> is that there is (currently) only one __autoload() function allowed,
> but
> this limitation should be removed once PHP5.1.0 gets rolled out.
>
>> thinking of setting up a url like /currentdir/packagename/classname,
>> mind you this is only a test but is it a
>> good or bad bad idea ?I have run into troubles getting get queries
>> because its calling the
>> classname in the query alreadyso /packagename/classname?test=1 doesnt
>> work.
>>
>
> Using rewrite rules would be another way you could do it. Or you could
> have one "main" include file that would set some variable (call it
> $base_dir) that points to the filesystem folder that is your root
> directory. I.e.
>
> <?php
>
> /** "main" include file */
> $base_dir = dirname(__FILE__) . '/';
>
> /** now include some other global classes relative to this $base_dir */
> include_once ($base_dir . 'path/from/docroot/to/class.php');
>
> ?>
>
> <?php
>
> /** some other script loads main config file */
> require_once '/path/to/main.php';
>
> /** now get your required classes */
> require_once $base_dir . 'path/to/some/class.php';
>
> ?>
>
> --
> Teach a man to fish...
>
> NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
> STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
> STFM | http://php.net/manual/en/index.php
> STFW | http://www.google.com/search?q=php
> LAZY |
> http://mycroft.mozdev.org/download.html?
> name=PHP&submitform=Find+search+plugins
Navigation:
[Reply to this message]
|