1

I have a menu in a block and this is my code in that block that is in sidebar second:

<?php
  $url=$base_url.'/drupal';
  echo
  '<ul>
  <li><a href="'.$url.'/article/1">One</a></li>
  <li> <a href="'.$url.'/article/2">Two</a></li>
  </ul>';
?>

it is working correctly, but return and red alert:

Notice: Undefined variable: base_url in eval() (line 2 of C:\xampp\htdocs\drupal\modules\php\php.module(80) : eval()'d code).

1 Answer 1

0

You need to define it as a global variable first:

global $base_url;

So that your code is now:

<?php
global $base_url;
$url=$base_url.'/drupal';
echo
'<ul>
<li><a href="'.$url.'/article/1">One</a></li>
<li> <a href="'.$url.'/article/2">Two</a></li>
</ul>';
?>

Then you may don't need drupal in your $url variable. and it would become:

$url=$base_url;
4
  • Can you please tell me more, for example put it in my code.
    – user45261
    Commented Mar 16, 2015 at 5:29
  • You just add that one line in the starting of your code, as shown in the updated answer.
    – shivams
    Commented Mar 16, 2015 at 5:32
  • Thanks, Drupal Shows a green box with this message: The block configuration has been saved.. :)
    – user45261
    Commented Mar 16, 2015 at 5:37
  • Okay. So, no error message now, right? Happy to help :)
    – shivams
    Commented Mar 16, 2015 at 5:40

Your Answer

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