ruudy
ruudy

Reputation: 491

hook_menu not working for me, neither helloworld example

I waste all day fighting with drupal 7 hook_menu, days ago all was working when i create new modules, new menu entries, etc.

Im developing a cron, depends of 1 parameter, its generate a file to output, or read other file (input).

I trying to define a simple url to test the cron, and when i put ...lec_profile_cron in the brosers, it works, but if try ....companies_cron/1 or just companies_cron o other name y put at $items['route'], its doesnt works.

I tried to clean cache, memcached, use drush rr, all and dont understand what is happen.

I tried a lot of combinations and examples like the helloword_hello menu option in a new module i create called helloworld, and its returns 404 not found.

// CRON TEST
$items['companies_cron/%out'] = array(
    'title' => t('Test cron'),
    'page callback' => 'lec_profile_cron',
    'page arguments' => array(1),
    'access arguments' => array('administer lec profile configuration')
);

function lec_profile_cron($out)
{
    // CRON OUT
    if ($out == 1) {
        //do stuff
    } else {
        //CRON IN
    }
}

Maybe was a stupid thing, but i cant find...

Ty in advice.

Upvotes: 0

Views: 82

Answers (1)

Sibbo
Sibbo

Reputation: 78

According to the documentation I think this will work better. You dont need th %out for args in your $items and I also think you missing the trailing comma on 'access arguments' which I've added and also returning something.

$items['companies_cron'] = array(
'title' => t('Test cron'),
'page callback' => 'lec_profile_cron',
'page arguments' => array(1),
'access arguments' => array('administer lec profile configuration'),
return $items;

);

function lec_profile_cron($out = 0){
// If companies_cron/ is called, $out takes default value of 0
// If companies_cron/1 is called, $out value will be 1
// To pass multiple args, like companies_cron/1/2, you would require further params with defaults like $out = 0, $in = 0 ...

// CRON OUT
if ($out == 1) {
    //do stuff
} else {
    //CRON IN
}
};

Upvotes: 0

Related Questions