[development] url as callback argument

Iñaki Lopez inaki.lopez at gmail.com
Tue Feb 3 15:08:11 UTC 2009


$items[] = array(
   'path' => 'admin/settings/featured-comments/feature',
   'title' => t('featured comment'),
   'callback' => 'feature_comment',
   'callback_args' => $_GET['cid'],

should be..

$items[] = array(
   'path' => 'admin/settings/featured-comments/feature/%',
   'title' => t('featured comment'),
   'callback' => 'feature_comment',
   'callback_args' =>array(4),
...

try this..


On Tue, Feb 3, 2009 at 12:46 PM, Steven Jones <darthsteven at gmail.com> wrote:

> I'm not how to relates to development of Drupal, so I'll try to kill
> this thread, here's the main issue:
>
> Your hook_menu returns an item with a 'callback_args', key, that key
> should be: 'callback arguments' and the value should be an array of
> arguments to pass to the callback.
>
> http://api.drupal.org/api/function/hook_menu/5
>
> Regards
> Steven Jones
> ComputerMinds ltd - Perfect Drupal Websites
>
> Phone : 0121 288 0434
> Mobile : 07951 270 026
> http://www.computerminds.co.uk
>
>
>
> 2009/2/3 cooper Quintin <cooperq at cooperq.com>:
> > Hello all,
> > I am writing a module and I am trying to use a url as a callback
> > argument, but it does not work.  Here is the code:
> >
> > $items[] = array(
> >    'path' => 'admin/settings/featured-comments/feature',
> >    'title' => t('featured comment'),
> >    'callback' => 'feature_comment',
> >    'callback_args' => $_GET['cid'],
> >    'access' => user_access('administer comments'),
> >    'type' => MENU_CALLBACK
> >  );
> >
> > and the callback function:
> > function feature_comment($cid) {
> >  $comment = _comment_load($cid);
> >  db_query("UPDATE {featured_comments} SET featured=1 WHERE cid=%d",
> $cid);
> >  drupal_goto("node/$comment->nid");
> > }
> >
> > going to an example url:
> > http://example.com/admin/settings/featured-comments/feature?cid=10840
> > gives the following error: warning: Missing argument 1 for
> > feature_comment() in
> >
> /var/www/html/sites/all/modules/featured_comments/featured_comments.module
> > on line 149.
> >
> >
> > So my question is, what is the best way to use parts of the linked url
> > as a callback argument for a function, because obviously it is not what
> > I am doing!
> > Thanks,
> >
> > --
> > Cooper Quintin
> > Freelance Programmer, Indymedia Journalist
> > http://CooperQ.com
> > (510) 827-5382
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20090203/4dd464b7/attachment.htm 


More information about the development mailing list