0

I inherited someone else's project.

I see he created a module called bcompanies.module. In that module file I see this:

function bcompanies_menu() {
    $items['company'] = array(
        'title'     => 'Company',
        'page arguments'    => array(1),
        'page callback' => 'company_page',
        'access callback'   => TRUE,
        'type'          => MENU_CALLBACK
    );
    $items['company_page2'] = array(
        'title'     => 'Company',
        'page arguments'    => array(1),
        'page callback' => 'company_page',
        'access callback'   => TRUE,
        'type'          => MENU_CALLBACK
    );

}

function company_page()
{
      return 'hello world';
}

When I go to the url http://site.com/company, I see the text "hello world". When I go to the url http://site.com/company_page2, I am redirected to http://site.com/welcome . Does anyone know why the second url keeps redirecting me while the first does not, even though they seems exactly the same in terms of set up?

I did a test and wrote a die() statement in company_page(), that forced it to not redirect. But that's not that great, because it prevents subsequent drupal hooks from firing.

Additional Notes

I noticed that if I login as an admin user, then there is NO REDIRECT when i go to http://site.com/company_page2 - I see hello world wrapped nicely by the header html template and the footer html template. The redirect only happens when i login as a regular user going to that page.

So is this a permission/role issue? But I never set the permission or role or anything...

0

There can not be a permission issue in your code (because you code is very simple:) ). Just try to change your code as documentation says:

function bcompanies_menu() {
    $items = array();

    $items['company'] = array(
        'title'     => 'Company',
        'page arguments'    => array(), // I removed arguments because of callback function doesn't require in your case;
        'page callback' => 'company_page',
        'access callback'   => 'user_access', // I changed your access callback, it's a bad practice to set just TRUE as an access callback
        'access arguments' => array('access content'),
        'type'          => MENU_CALLBACK
    );
    $items['company_page2'] = array(
        'title'     => 'Company',
        'page arguments'    => array(),
        'page callback' => 'company_page',
        'access callback'   => 'user_access',
        'access arguments' => array('access content'),
        'type'          => MENU_CALLBACK
    );

    return $items; // I added this line, because I don't know you 're returning a value in your module or not..

}

function company_page()
{
      return 'hello world';
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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