0

I’m taking first steps in building a module for Drupal 7 and am trying to create a static page within hook_menu function. In the $items array, for ‘page callback' I create an very simple function named ‘semi_static_page’. This simple function returns some html. the code is below.

$items['admin/config/media/tsoundcloud/config/soundcloud_static'] =             array(
    'title' => t('Semi Static Page'),
    'description' => 'Temp page to show data',
    'page callback' => 'semi_static_page',
    'access arguments' => array('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
    );

function semi_static_page(){
  $output = 'this is some output, etc…….’;
  return $output;
}

But this page generate the following error.

Fatal error: Unsupported operand types in /Users/tomcarden/Sites/sweetteas/includes/form.inc on line 1079

How can this be resolved? Ultimately I want to load an .inc in the semi_static_page function.

thanks in advance!

0

$output = 'this is some output, etc…….;

If you see in the above line, you are using wrong sign, which I have highlighted after ...... That is wrong. It should be '

Above isuue is for sure!!!!


Other just my suggestion, As I am also learning Hooks, may be TOTALLY WRONG but for your attention.

I have changed code as below and after that, I have written my point..

/**
 * Implements hook_menu()
 */
function mymodule_menu() {
  $items['admin/config/media/tsoundcloud/config/soundcloud_static'] = array(
    'title' => 'Semi Static Page',
    'description' => 'Temp page to show data',
    'page callback' => 'mymodule_semistaticpage', 
    'access arguments' => array('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
    );
    return $items;
 }

/**
 * Page callback
 */
function mymodule_semistaticpage(){
  $output = 'this is some output, etc…….';
  return $output;
}

The following points are for code which you have posted in main-question, and I have corrected those in above code,

  • See function name, it should start with module name.
  • The _page(), may creating confusion as some hook has _page() part..so I did change function name to mymodule_semistaticpage()
  • where is return $items;?
  • I think title do not need, t()?
0

Your current problem is very clearly mentioned in error statement , you need to replace (’) with (') without parentheses of-course.

other suggestions: 1: Title field do not require t() function 2: Description field should be written in t() function 3: Never ever forget to return $items array. 4: It is customary to start call back function names with your module name. 5: Always document your code for future purposes. 6: Your call back function should return content in a theme-able formate for example ('#type' => 'markup') etc

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.