1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Find out where I am from XenForo_FrontController

Discussion in 'XenForo Development Discussions' started by Marc, May 26, 2011.

  1. Marc

    Marc Well-Known Member

    Hi Guys,
    Probably an easy one, but cant seem to figure it. Please could someone let me know how to find out what the current controller is from a XenForo_FrontController object?

    To be more specific, I would like to see when I am www.myForum/account/personal-details

    Cheers
     
  2. ragtek

    ragtek Guest

    If you have enabled the debug mode, you'll see the controller on mouseover of the debug link in the footer

    Timing: 0.1320 seconds Memory: 4.606 MB DB Queries: 12
     
  3. Rigel Kentaurus

    Rigel Kentaurus Well-Known Member

    You mean programatically? You can probably do instanceof to check what class the current controller is
     
  4. Marc

    Marc Well-Known Member

    Sorry I mean as in I am trying to do the following:

    if($fc == 'dcXenMapMe_ControllerPublic_Index')
    {
    die('this is the map');
    }

    however this is not right somehow (or at least it doesnt die LOL) ....... Using a listener on front_controller_post_view ...

    Lovin the link on that debug though. Didnt realise it gave yo all that information until I just clicked on it LOL
     
  5. Rigel Kentaurus

    Rigel Kentaurus Well-Known Member

    I have written a bunch of hacks and it is really rare that I need to do this at the FrontController level, what are you trying to do? My first instinct is .. you don't need to do that.

    That said .. this code would detect which one is the active controller at that particular code event. In this example, it is looking to see if it is
    XenForo_ControllerPublic_Account

    Code:
            $routeMatch = $this->route();
            $reroute = array(
                'controllerName' => $routeMatch->getControllerName(),
                'action' => $routeMatch->getAction()
            );
            $action = str_replace(array('-', '/'), ' ', strtolower($reroute['action']));
            $action = str_replace(' ', '', ucwords($action));
            if ($action === '')
            {
                $action = 'Index';
            }
            $controller = $this->_getValidatedController($reroute['controllerName'], $action, $routeMatch);
            if ($controller instanceof XenForo_ControllerPublic_Account)
            {
                exit;
            }
    
     
  6. Rigel Kentaurus

    Rigel Kentaurus Well-Known Member

    If you want to EXTEND personal details, this is the correct way to do it.
    Please note, this is the basic outline, not a working example.

    1) Create a listener, that will listen on load_controller
    2) on that listener, add the following

    Code:
        public static function listen($class, array &$extend)
        {
            if ($class == 'XenForo_ControllerPublic_Account')
            {
                $extend[] = 'WHATEVER_YOUR CLASS';
            }
        }
    
    3) and, create your class. The stub will be

    Code:
    class WHATEVER_YOUR CLASS extends XFCP_WHATEVER_YOUR CLASS
    {
    
    public function actionPersonalDetails()
        {
            //your code here
            parent::actionPersonalDetails();
        }
    }
    
    With this, every time the controller for account gets called, for that particular action, your code will be executed as well. Add more actions as necessary.
     
    Marc likes this.
  7. Marc

    Marc Well-Known Member

    Indeed that is what I am trying to do!!! :)

    Or to be more specific, I am trying to look at a specific profile field when the profile is saved. In this case the location field.
     
  8. ragtek

    ragtek Guest

    IT's IMHO better to do this inside the user datawriter!
     
  9. ragtek

    ragtek Guest

    reason:

    if you create "automatic" users / users in the acp you're code won't run, if you do this in the controller!
    If you do it in the datawriter, it will happen EVERYTIME you change/create a user.

    Also it's maybe good, to include a delete method, if the user is deleted => delete his mark
     
    Marc likes this.
  10. Marc

    Marc Well-Known Member

    Ya know one day I hope I'm as good as you lot LOL

    OK so use load_class_datawriter instead .. I am assuming then it may be better to add my marker detail within the user table itself in new fields, since this way when the user is deleted they would be deleted anyway along with the entry in the database?
     
  11. ragtek

    ragtek Guest

    yes, this is also possible

    Some prefer not to change the original tables, but i don't care^^
    Just be sure that you create a REALLY UNIQUE name (for example, i add always ragtek_ as prefix).
    So i'm sure that xenforo or non other add-on will have the same table
     
    Marc likes this.
  12. Marc

    Marc Well-Known Member

    Cheers for the tip. Would always prefix with something unique when adding to a table. Databases are about the one thing I do know quite a lot about LOL ... Guess everyone has to know somethin LOL
     
    ragtek likes this.

Share This Page