2

I've built a custom module to get cloudinary images and it works great. However, a bug has cropped up. You can navigate to /cloudinary/resource/public_id and it gets the image with public_id. On cloudinary there is now the ability to specify folders, so a public id could be something like "unitedstates/public_id". This is wrecking my hook_menu:

function cloudinary_menu() {    

    ...    

    $items['cloudinary/resource/%'] = array(
        'access callback' => TRUE,
        'page callback'  => 'get_resource',
        'page arguments' => array(2)
    );
...

Is there any way to specify that anything after /% should be passed?

2 Answers 2

2

I don't think so, but you can kludge something together pretty easily:

function get_resource() {
  $resource_path = implode('/', func_get_args()); 
}

Results:

  • cloudinary/resource/unitedstates/public_id => unitedstates/public_id
  • cloudinary/resource/unitedstates/foo/bar/public_id => unitedstates/foo/bar/public_id

And so on

0
2

Additional arguments are still sent to page callback functions.

You might try doing a check for additional arguments:

function get_resource($id) {
  $args = func_get_args();
  if (count($args) > 1) {
    $id = end($args);
  }
  /** rest of your code **/
} 

This way if the public id was "unitedstates/public_id", func_get_args() would return two items, the second one being "public_id" which would be set as the $id if there is more than one argument. Note this will always set the last argument as $id if there is more than one.

1
  • Nice one. I used func_get_args() Feb 16, 2015 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.