Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Magento detection of classes
 
srinigenie
Guru
 
Avatar
Total Posts:  539
Joined:  2008-02-04
 

Hi all,

I am wondering how magento detects classes present in core, community, local and lib folders without actually mentioning the entire path. On checking this I looked at the father of all magento classes - app/Mage.php.  The below statements seem to set the include path:

Mage::register('original_include_path'get_include_path());

/**
 * Set include path
 */
$paths[] BP DS 'app' DS 'code' DS 'local';
$paths[] BP DS 'app' DS 'code' DS 'community';
$paths[] BP DS 'app' DS 'code' DS 'core';
$paths[] BP DS 'lib';

$app_path implode(PS$paths);

set_include_path($app_path PS Mage::registry('original_include_path'));

But this should mean that any class in these folders should get detected by magento, right?? So I went ahead and placed a new class inside apps/code/local (placed a random PHP class). I tried to access this PHP class from elsewhere in magento, say, a phtml file (template) and found that magento was not able to detect this :(.

I am still wondering how magento detects its core classes in the flow. Any pointers welcome smile.

Thanks!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
srinigenie
Guru
 
Avatar
Total Posts:  539
Joined:  2008-02-04
 

Am checking this one out and will update on my findings. Meanwhile if anyone can provide some quick pointers, that would help as well smile.

Thanks!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
srinigenie
Guru
 
Avatar
Total Posts:  539
Joined:  2008-02-04
 

Finally got this one.... seems Magento or rather set_include_path searches for a class file as per the class name-
So if a class POC_Chat needs to be found, it searches for a class Chat.php under POC directory in any of the included paths.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mela
Jr. Member
 
Total Posts:  16
Joined:  2009-03-17
 

As far as I understood this should be a “namespace implementation for PHP”.  Another userful thing i stumbled on is, that Magento expects that the first letter of a directory name is Uppercase (nevertheless it is possible to specify a class like my_funny_class in the Magento .xml config files and Magento Expects it to be in My/Funny/Class).  A little inconsequent at that place…

Cheers,
mela

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top