Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 590 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optional argument in Drupal hook_menu implementation

#1
How can I set one of the page arguments in my drupal menu item as an optional page argument?

I have

$items['activities_list/%/%']=array(
'title callback' => 'activities_list_title',
'title arguments' =>array(1),
'description' =>'All the Indicators divided by Coutry',
'page callback' => 'activities_list',
'access arguments' => array('access ppi'),
'page arguments' => array(1,2)
);

If I call activities_list/76 for example without a third argument I will receive a page not found error. How Can I set the Third parameter as an optional one?

Thanks!
Reply

#2
I don't think you can. If you did this instead with only one wildcard:

$items['activities_list/%']=array(
'title callback' => 'activities_list_title',
'title arguments' =>array(1),
'description' =>'All the Indicators divided by Coutry',
'page callback' => 'activities_list',
'access arguments' => array('access ppi'),
'page arguments' => array(1,2)
);

This will then work for a URL like **activities_list/foo**, but if you then had a URL like **activities_list/foo/bar** you can still get the value of **bar** in the page callback as it is still passed to that function by **'page arguments' => array(1,2)**.

Or alternatively you can call it by using **arg(2)** in your page callback.
Reply

#3
It's easier than you think :). Don't set any arguments in your path and just pass them to your "page callback" function.

$items['activities_list']=array(
'title callback' => 'activities_list_title',
'description' =>'All the Indicators divided by Coutry',
'page callback' => 'activities_list',
'access arguments' => array('access ppi'),
);

And the page callback function would look like this:

function activities_list($arg1, $arg2)
{
// Your code goes here...
drupal_set_title(activities_list_title($arg1, $arg2));
}

You can alter the page title using the following code. (Not tested, kindly let me know if it worked):

function activities_list_title($arg_1, $arg_2)
{
$title = "";
// Your code goes here
return $title;
}

Hope this helps... Muhammad.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through