TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-14-2010, 03:44 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Getting classname where function was called from

How would I get the classname of a class where I called another class's function?

one.php
PHP Code:
class One
{

     public static function 
test()
     {

          echo 
Two::test();

     }


two.php
PHP Code:
class Two
{

     public static function 
test()
     {

         return 
'You called this from: ' $something;

     }


Calling One::test() would echo out:
You called this from: One, or
You called this from: one.php, or
You called this from: path/to/file/one.php

Is that possible??
__________________
Tanax is offline  
Reply With Quote
Old 06-14-2010, 08:16 PM   #2 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

php Code:
echo get_class($this);
echo __FILE__;
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 06-14-2010, 08:52 PM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

If I'm understanding what you want, it's not as simple as Enfernikus makes out. However, it would be possible: parsing the contents of debug_backtrace might be your best bet.
Salathe is offline  
Reply With Quote
Old 06-14-2010, 10:11 PM   #4 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

I misunderstood his request, side effect of trying to aid when at work in the midst of a coding frenzy. There's no easy method of doing what you'd like but as Salathe said, debug_backtrace would most likely be your best option.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 06-16-2010, 02:44 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Didn't work quite as I wanted/expected, but thanks for the help!
__________________
Tanax is offline  
Reply With Quote
Old 06-16-2010, 05:52 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

So, have you got the issue solved? Have any more questions? It's nice being thanked, but the thread has been kind of left hanging.
Salathe is offline  
Reply With Quote
Old 06-17-2010, 08:13 PM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Haha, it's solved for the moment but not the way I wanted.
I have an HMVC framework with modules, I wanted so when I load a view, it will first check if the view exists in the current module - IF the view was loaded from a module - and then if not found there check the regular application/views/ folder for the view-file.

Kinda like this:
modules/welcome/controllers/welcome.php
PHP Code:
View::factory('website/index'); 
That will check modules/welcome/views/website/index.php, if found, render it.
If not found, check application/views/website/index.php, if found, render it.
If not found, check all other modules views directories, if found, render it.
If not found, generate error message.

On the other hand, if I do like this:
application/controllers/welcome.php
PHP Code:
View::factory('website/index'); 
It will check application/views/website/index.php, if found, render it.
If not found, check all modules views directories, if found, render it.
If not found, generate error message.

All of that is quite simple, takes some work but I can make that work.
The thing that complicates it is that I want to be able to load a view from within a view.

Like so:
modules/welcome/views/website/index.php
PHP Code:
<?php echo View::factory('footer'); ?>
It will check modules/welcome/views/footer.php, if found, render it.
If not found, check application/views/footer.php, if found, render it.
If not found, check all other modules views directories, if found, render it.
If not found, generate error message.

I think you get the point..
So somehow I need to check if the factory() call came from a class, if so, check which class, get the name, get the location. If not from a class - but from a viewfile - get the location of that viewfile.
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Next class project? allworknoplay The Lounge 6 04-18-2009 08:33 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
How can I track errors from a called function? tony Absolute Beginners 13 08-19-2008 10:34 PM


All times are GMT. The time now is 11:47 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design