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.
A lil confusion about $Args

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?
0
Best Answers
-
vrijvlinder MVP
Look inside class.controller.php
/** * This is typically an array of arguments passed after the controller * name and controller method in the query string. Additional arguments are * parsed out by the @@Dispatcher and sent to $this->RequestArgs as an * array. If there are no additional arguments specified, this value will * remain FALSE. * ie. http://localhost/index.php?/controller_name/controller_method/arg1/arg2/arg3 * translates to: array('arg1', 'arg2', 'arg3'); * * @var mixed */ public $RequestArgs;
5
Answers
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.
Look inside class.controller.php
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
in any hook
$Args
are the event arguments.the same as
$Sender->EventArguments
and array or arguments, what they are depend on the hook,$Args
is just a convenience reference.grep is your friend.
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?)
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 rulesHowever 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
):grep is your friend.
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.