So confused about arg(...)
I'm working on a hook_preprocess_page and it seems to be behaving strangely. I have: drupal_set_message('stuff '. arg(0) . '/' . arg(1)); $variables['nancy'] = $hook . arg(0) . '/' . arg(1); In exactly that order, with no intervening lines. Displaying the variable in the page.tpl.php shows "page taxonomy/term" but the message shows "stuff r/ms" (even if I refresh the page, or clear the cache). How can this be happening? Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
Call me old school, but calling the same function with the same argument twice in a row is wasteful. I see this tendency to just call the same thing a lot rather than storing it in a variable and reusing it, and I don't like it. $a0 = arg(0); $a1 = arg(1); $path = "$a0/$a1"; drupal_set_message('stuff' . $path); $variables['nancy'] = $hook . $path; This does not address why you are seeing what you are seeing. Use a debugger like xdebug to see what really is going on there. On Thu, Jan 14, 2010 at 10:49 AM, Nancy Wichmann <nan_wich@bellsouth.net>wrote:
I’m working on a hook_preprocess_page and it seems to be behaving strangely. I have:
drupal_set_message(‘stuff ‘. arg(0) . ‘/’ . arg(1));
$variables[‘nancy’] = $hook . arg(0) . ‘/’ . arg(1);
In exactly that order, with no intervening lines.
Displaying the variable in the page.tpl.php shows “page taxonomy/term” but the message shows “stuff r/ms” (even if I refresh the page, or clear the cache). How can this be happening?
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
-- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting. Simplicity is prerequisite for reliability. -- Edsger W.Dijkstra Simplicity is the ultimate sophistication. -- Leonardo da Vinci
Unless you are altering the registry, setting the status message won't show up on the current page, since they are already pulled in by template_preprocess_page (the first preprocess function). That means the message set in your preprocess function won't show up until the next page. Not sure if that's causing the problem or not, but it is something to keep in mind. Jamie Holly http://www.intoxination.net http://www.hollyit.net On 1/14/2010 11:14 AM, Khalid Baheyeldin wrote:
Call me old school, but calling the same function with the same argument twice in a row is wasteful. I see this tendency to just call the same thing a lot rather than storing it in a variable and reusing it, and I don't like it.
$a0 = arg(0); $a1 = arg(1); $path = "$a0/$a1"; drupal_set_message('stuff' . $path); $variables['nancy'] = $hook . $path;
This does not address why you are seeing what you are seeing. Use a debugger like xdebug to see what really is going on there.
On Thu, Jan 14, 2010 at 10:49 AM, Nancy Wichmann <nan_wich@bellsouth.net <mailto:nan_wich@bellsouth.net>> wrote:
I’m working on a hook_preprocess_page and it seems to be behaving strangely. I have:
drupal_set_message(‘stuff ‘. arg(0) . ‘/’ . arg(1));
$variables[‘nancy’] = $hook . arg(0) . ‘/’ . arg(1);
In exactly that order, with no intervening lines.
Displaying the variable in the page.tpl.php shows “page taxonomy/term” but the message shows “stuff r/ms” (even if I refresh the page, or clear the cache). How can this be happening?
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
-- Khalid M. Baheyeldin 2bits.com <http://2bits.com>, Inc. http://2bits.com Drupal optimization, development, customization and consulting. Simplicity is prerequisite for reliability. -- Edsger W.Dijkstra Simplicity is the ultimate sophistication. -- Leonardo da Vinci
Jamie Holly wrote:
setting the status message won't show up on the current page
Yes, I figured that out, but even if I refresh the page, the message is still screwy. Further more, right after this is "switch arg(0)" and it is trying to find a "case 'r'" rather than "taxonomy." Khalid Baheyeldin wrote:
calling the same function with the same argument twice in a row is wasteful
I agree, and I originally saved it to a variable, but changed it back when this weird stuff started happening. Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
On Thu, Jan 14, 2010 at 5:49 PM, Nancy Wichmann <nan_wich@bellsouth.net> wrote:
Jamie Holly wrote:
setting the status message won't show up on the current page
Yes, I figured that out, but even if I refresh the page, the message is still screwy. Further more, right after this is “switch arg(0)” and it is trying to find a “case ‘r’” rather than “taxonomy.”
Khalid Baheyeldin wrote:
calling the same function with the same argument twice in a row is wasteful
I agree, and I originally saved it to a variable, but changed it back when this weird stuff started happening.
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
drupal_add_js() in page template not working http://drupal.org/node/482542#comment-1666888 page.tpl.php -Theme implementation to display a single Drupal page. Available variables: $messages: HTML for status and error messages. Should be displayed prominently. http://api.drupal.org/api/drupal/modules--system--page.tpl.php Your drupal_set_message happens when $messages is already set, so you are not really changing the message but setting the message for the next page loading when in http://api.drupal.org/api/function/template_preprocess_page/6 new $message is set with $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : ''; status messages are stored in a $_SESSION['messages'] So if you want to add your message you should change the variable $message. In this way the result you get should be the same. ema -- Emanuele Quinto - www.wfp.org ------------------------------------------------------------------------------------------------------------------ My mother used to say to me, "Elwood" - she always called me Elwood - "In this world, Elwood, you must be oh-so smart, or oh-so pleasant." For years I was smart. I recommend pleasant, and you may quote me. ------------------------------------------------------------------------------------------------------------------
I just tried the code you gave and it works fine on my test site. arg() is a very simple function, so as long as you aren't accidentally sending in a second argument it should work fine. Jamie Holly http://www.intoxination.net http://www.hollyit.net On 1/14/2010 11:49 AM, Nancy Wichmann wrote:
Jamie Holly wrote:
setting the status message won't show up on the current page
Yes, I figured that out, but even if I refresh the page, the message is still screwy. Further more, right after this is "switch arg(0)" and it is trying to find a "case 'r'" rather than "taxonomy."
Khalid Baheyeldin wrote:
calling the same function with the same argument twice in a row is wasteful
I agree, and I originally saved it to a variable, but changed it back when this weird stuff started happening.
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
Nancy Wichmann wrote:
I’m working on a hook_preprocess_page and it seems to be behaving strangely. I have:
drupal_set_message(‘stuff ‘. arg(0) . ‘/’ . arg(1));
$variables[‘nancy’] = $hook . arg(0) . ‘/’ . arg(1);
In exactly that order, with no intervening lines.
Displaying the variable in the page.tpl.php shows “page taxonomy/term” but the message shows “stuff r/ms” (even if I refresh the page, or clear the cache). How can this be happening?
Because you're doing this in the page template, please note that your dsm() will be one refresh behind. I'm not sure that you've pasted the exact code you're using -- there's no space, for example, in your $hook . arg(0) but you show one in your output. I realize that is a trivial difference but it immediately makes me wonder if there are other trivial differences that may not be so trivial?
Earl Miles wrote:
Nancy Wichmann wrote:
I’m working on a hook_preprocess_page and it seems to be behaving strangely. I have:
drupal_set_message(‘stuff ‘. arg(0) . ‘/’ . arg(1));
$variables[‘nancy’] = $hook . arg(0) . ‘/’ . arg(1);
In exactly that order, with no intervening lines.
Displaying the variable in the page.tpl.php shows “page taxonomy/term” but the message shows “stuff r/ms” (even if I refresh the page, or clear the cache). How can this be happening?
Because you're doing this in the page template, please note that your dsm() will be one refresh behind.
Oh I meant to explain this. $messages is built in template_preprocess_page(). You're running in THEME_preprocess_page() which runs after template_preprocess_page(). $messages is already constructed, so anything you put in dsm() will go into the $_SESSION variable and show up in the NEXT processing of $messages.
participants (5)
-
Earl Miles -
Emanuele Quinto -
Jamie Holly -
Khalid Baheyeldin -
Nancy Wichmann