Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

A lil confusion about $Args

CrisCris New
edited May 2014 in Vanilla 2.0 - 2.8

Howdy everyone,

This is my 1st attempt to create my 1st plugin, and I need a lil bit help from you guys to clear some dark spots in my mind about $Args.
Does any1 can refer me to the correct place? I read many times the developer documentation (plugin quick start and more details), and it has never mentioned about it.

I know what $sender does, I only need to know is what $Args do.

Can I use that to pass arguments for my methods need?

Best Answers

Answers

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited May 2014
  • Options

    @vrijvlinder said:
    Arguments are a set of rules/variables the function needs to see completed before acting.

    http://www.php.net/manual/en/reserved.variables.argv.php

    http://www.php.net/manual/en/functions.arguments.php

    Thank you for the reply,

    Yeah I know about arguments, I just wanted to know what this $Args does in vanilla plugins. anyway finally I found what I've been looking for by adding this line in to a test plugin class.

    var_dump ($Args);

    Now I need to know what "RequestArgs" does. For an example what does $sender->RequestArgs do with this code:

    public function ProfileController_PeregrineBadges_Create($Sender, $Args) {
    $Sender->AddCssFile('peregrinebadges.css', 'plugins/PeregrineBadges');
    $Sender->UserID = ArrayValue(0, $Sender->RequestArgs, '');
    $Sender->UserName = ArrayValue(1, $Sender->RequestArgs, '');
    $Sender->GetUserInfo($Sender->UserID, $Sender->UserName);
    $Sender->SetTabView('peregrinebadges', dirname(FILE).DS.'views'.DS.'peregrinebadgestabview.php', 'Profile');
    $Sender->Render();
    }


    and finally, there is no complete documentation for the plugin building for vanilla right? I really don't know where to begin and I believe there are some special things to understand before we start coding (like this "RequestArgs" thing and bla bla..)

    Is there any reference page that contain all of this basic stuff to read? if it does, I would really appreciate if you can provide its link by posting it here.
    Thanks.

  • Options

    OK everything is clear now :)
    Another little help,

    Is that possible to grab arguments from a method's to another my plugin's custom magic method? for an example:

    I need to run a preg match after the user enter his email when he is registering,
    so I need to collect arguments of the EmailAvailable method in usercontroller? (in this case: The registration email of the user when he is registering)

    or do I need to create a route from emailavailable to someCustomMagicmethodOfMyPlugin and after it done, how can I forward it back to the emailavailable method "with its arguments"
    (I mean how can I manually trigger the EmailAvailable method after my customCode Finished?)

  • Options
    x00x00 MVP
    edited May 2014

    If you want to control registration. use the hooks associated with that.

    In 2.1 you have

    EntryController_RegisterValidation_Handler

    You can add validation $Sender->UserModel->Validation there is a specific format for regexp rules

    However you might prefer the

    UserModel_BeforeRegister_Handler

    In that case you can just refer to $Sender->Validation

    It compatible with older versions and is used with all kinds of registration method so you don't have to worry if it has been added to one. RegisterValidation might not be fired on all of them.

    The way to do the regex validation is like so (assuming you have got the validation instance as $Validation):

    $Validation->AddRule('EmailCheck','regex:`^someregexp`i');
    $Validation->ApplyRule('Email', 'EmailCheck', 'Email is invalid, yada yada!');
    

    grep is your friend.

  • Options

    Btw in php objects are passed by reference

    So if you use a custom method inside a hook, and pass it $Sender, there i no need to 'pass it back'. There is only one Sender instance from that hook.

    However if for whatever reason you need to pass thing around such as from an earlier hook, just stash it in a property variable.

    grep is your friend.

Sign In or Register to comment.