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

Sunday, July 12, 2009

Create CVS project

This is a basic how-to that walks you through the steps of using command line CVS to get your new module, theme, translation, or installation profile project into Drupal's contributions repository. The CVS reference guide for module maintainers and CVS reference guide for theme maintainers cover some additional, advanced tasks.

Before you start

The first thing you need to do before you start is to make sure that your code is ready for its first release. If your code is not yet ready for release, then it is too soon to contribute it as a project on drupal.org. You should also take some time to figure out the directory structure and file names for your code. Once you create your project, it will become very difficult to rename files and move directories.

You will also need to learn about CVS (Concurrent Versioning System), which is the source-code control and versioning system used in the Drupal project to manage source code for projects, versions, and releases. You should familiarize yourself with the information in the Drupal and CVS guide before creating your project. You will also need to apply for a cvs account before you can create a new project.

In preparation for adding your code to CVS, you should also add a CVS $Id$ tag to all of the files in your project. The Id tag should be at or near the top of each file, and for PHP, CSS, JS, and .info files, it needs to be embedded in a comment. When you check the file into CVS, the CVS system will expand the tag to add information about the check-in and version. Here are the lines to add:

  • // $Id$
    inside the in a PHP file, or in a JavaScript file
  • /* $Id$ */
    in a CSS file
  • ; $Id$
    in a .info file
  • $Id
    in a plain text file

You will also need to choose a namespace for your project, also known as the short project name. The short project name must be unique among all projects on drupal.org, whether they are modules, themes, or install profiles, and should start with a letter and contain only letters and underscores (which should be used between words). Change the directory name for your project to the chosen short project name now, and you might also want to change the names of files and functions within your project to match that name.

Create a project page

Once your project is ready for release, and you have a CVS account, the first step in making it into a drupal.org project is to create a project page on drupal.org for your project. A few notes:

  • In the Project type field, choose "module", "theme", "translation", or "install profile", depending on the type of project you are trying to create. Do not choose "Drupal project" or "Theme engine".
  • Enter the full name of your module, theme, profile, or translation in the "Full project name" field.
  • Enter the short project name you chose above in the Short project name field.
  • The Full description field is what will appear in the body of your project page on drupal.org -- see Best Practices for information on what to put in this section.
  • Initially, the Resources section will probably be blank, but you can go back and edit it later.
  • Use the short name to construct the CVS directory name, in subdirectory "modules", "themes", "profiles", or "translations" (for example, if your short name for a module is "my_module", enter /modules/my_module/ for the CVS directory). (Note that, if you're following along in these directions, you're telling Drupal.org the CVS directory before you actually create it using CVS. That's okay.)

Add your code to the repository

The next step is to check the code you have written into CVS. Here are the shell commands you will need to use (assuming a Unix/Linux system):

  1. export CVSROOT=:pserver:cvsusername@cvs.drupal.org:/cvs/drupal-contrib
    Replace "cvsusername" with your actual CVS user name. This command tells your CVS program which repository you want to use, and what your user name is.
  2. cvs login
    This command logs you in to the CVS repository on drupal.org. You will be asked for your CVS password.
  3. cvs checkout -l contributions/modules
    Substitute "themes", "profiles", or "translations" for "modules" if you are creating a theme, profile, or translation project rather than a module. This command checks out the appropriate section of the contributions repository -- the -l tells CVS not to download all of the files in the directory, but instead to grab only the directory itself (a "local" copy). You should see something like this on your screen: cvs checkout: Updating contributions/modules
  4. cd contributions/modules
    mkdir your-short-name
    cp -r path-to-your-local-copy-of-project/* your-short-name
    Again, substitute "themes", "profiles", or "translations" for "modules" if you are not creating a module. Also, substitute the short name you chose above for your project for "your-short-name". These commands will copy your existing source code into a new directory of the contributions directory you checked out, in preparation for checking it into CVS.
  5. cvs add your-short-name
    This command tells CVS that you want to add your new directory to the CVS repository. You should see a long list of all the files in your project directory listed with a "?" in front of them returned after you press enter.
  6. cvs add your-short-name/*
    This command tells CVS that you want to add all the files in your new directory to the CVS repository. You should see a long list of all the files in your project directory listed with "cvs add " in front of them returned after you press enter. If your module has subdirectories, you will need to then cvs add each subdirectory and the files within each subdirectory as well.
  7. cvs commit -m "Pertinent message about what you are committing" your-short-name
    This command finally commits your changes to the CVS repository (i.e. adds your directory and its files). You should see several messages, hopefully indicating all of your files have been added to CVS. The commit mesages handbook page has more information on how to format CVS commit messages.

Create a release

In order for people to see your project in the list of modules, themes, installation profiles, or translations on drupal.org, you also need to create at least one release. You create a release by first creating a tag or branch of your project in CVS, and then creating a release node on drupal.org; this is explained fully in the Managing releases section of this guide.

Add a handbook page

You should have at least basic documentation included with your module. Beyond README and INSTALL files, it is recommended that you also create a new handbook page on Drupal.org in the Contributed modules section. To do that, navigate the correct section for your module and then click the "Add child page" link at the bottom of the page. You can now create a new page titled with the name of your module, with a brief description of the module, basic installation and configuration instructions, and a link to the project page in the body of the page. After you submit that page, you can add more child pages to it if you wish to expand and organize your module's documentation.


Source: http://drupal.org/node/100748

Friday, July 3, 2009

PHP MySQL MyAdmin Login

If You are using WAMP , then this might be a trouble, once u change the root password, and then u try to connect to localhost , and get this message :

#1045 - Access denied for user 'root' 'localhost' (using password: NO)


you should navigate to " C:\wamp\apps\phpmyadmin3.1.3.1\config.inc.php or go to folder and use search to find the file
config.inc.php

here you just have to change the user to root, or one u have used , and password to what you have set.

$i++;
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'yourPassword';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;


Try connecting to MySql Again .... bingo it works


Changing USER ID Password in MySql

Setting the MySQL Root Password
You now should have MySQL running in a DOS console. Open another console window using one of the two methods described above. You need to change the default root password on your MySQL Windows install. Write your password down somewhere so you don't forget it.

 TYPE c: TYPE cd mysql\bin TYPE mysql -u root 

At the MySQL prompt:

 TYPE SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpasswordhere'); TYPE DELETE FROM mysql.user WHERE Host='localhost' AND User='""'; TYPE FLUSH PRIVILEGES; 

These commands change your root password and remove another out-of-the-box root user to improve your security.