Wednesday, September 9, 2009

may_cache

parameter passed to hook_menu($may_cache)
$may_cache A boolean indicating whether cacheable menu items should be returned. The menu cache is per-user, so items can be cached so long as they are not dependent on the user's current location. See the local task definitions in node_menu() for an example of uncacheable menu items.
START PHP TAG
function
hook_menu($may_cache) {
global $user;
$items = array();

if ($may_cache) {
$items[] = array('path' => 'node/add/blog', 'title' => t('blog entry'),
'access' => user_access('maintain personal blog'));
$items[] = array('path' => 'blog', 'title' => t('blogs'),
'callback' => 'blog_page',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
$items[] = array('path' => 'blog/'. $user->uid, 'title' => t('my blog'),
'access' => user_access('maintain personal blog'),
'type' => MENU_DYNAMIC_ITEM);
$items[] = array('path' => 'blog/feed', 'title' => t('RSS feed'),
'callback' => 'blog_feed',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
}
return $items;
END PHP TAG
}

Tuesday, September 8, 2009

Add a PHP script to CCK

If you want to add a CCK field with values which are available in other database tables, then you might just add the field , select drop down values , and in the allowed values, open the cascade to see PHP Values allowed.
In the textarea enter the code : ( no need for starting and ending tags)
-------------------------------------------------------------
$options = array('' => t('- select a product -'));
$res = db_query('SELECT title FROM {node},{uc_products} WHERE node.nid = uc_products.nid');
while ($o = db_fetch_object($res)) {
$options[$o->title] = $o->title;
}
return $options;
--------------------------------------------------

this will populate the drop down box with db enteries in products table with the product nodes