I have been reading about pathauto in combination with either panels or views. I think I understand how to set this up but its not really helping me do exactly what I need for my custom modules that use custom tables.
I have set up some custom modules for clients, but when it came to passing $_GET values I always just used "dirty" URL.
Typically I will use hook_menu() to define a MENU_CALLBACK...
$items['products'] = array(
'title' => 'Products',
'page callback' => 'show_products',
'access arguments' => array('view products'),
'type' => MENU_CALLBACK,
);
... so www.client.com/products shows the products pages.
I then use $_GET values to populate page data - www.client.com/products?p=product-name
if(isset($_GET['p'])) {
$productName = $_GET['p'];
//get product model from db, view the product, etc.
}
What I would like is a friendly URL like this: http://www.client.com/products/product-name
Obviously this points to http://www.client.com/index.php?q=products/product-name
I would like it to point to http://www.client.com/index.php?q=products&p=product-name
Is there any easy way to do this that I am overlooking? I don't want to have to use nodes for everything and then some custom views/panels/etc stuff. It all seems really convoluted to me. I want to use my own custom tables, forms, etc that I am used to in custom module development.
Can I set something up using custom_url_rewrite_inbound() perhaps? I am not very familiar with mod_rewrite but this seems like something that could be done using this function, but I am confused.
Comments
Here is one approach, define
Here is one approach, define your menu hook as
The callback as
and use a path like
products/product-name.If product name is optional declare the callback as
Awwwww yeaah
Thanks! I totally overlooked page_arguments... wow. Really easy to implement. Here's a quick example of the working code in case anyone finds this thread someday....
Example string: http://www.client.com/products/bart-simpson-shirt/x-large
Will return:
Products
bart-simpson-shirt
x-large
^__^
this is awesome
Using arg(0) to assign a variable?
Was looking for the same thing. This might be a simple solution.
Edit: read up on check_plain() and check_url() as well.