problem with PHP argument code

jdidelet's picture

Hi all,

Anyone can help me ? I have a problem in Views 2 with PHP argument code (well, I probably a problem with my code). I push this code but it's seem wrong and I don't understand why (I choose Taxonomy: Term ID (with depth) for argument) :

if (arg(0) == 'products') {
$arg_array = arg();
$value = end($arg_array);
}
return $value;

Probably I miss somethings.

Regards,
Julien
PS : My URL is like that : name-of-my-site.dev/products/taxonomy-name1/taxonomy-name2/...

Groups:
Login to post comments

Hi Julien, You shouldn't need

dalin's picture
dalin - Wed, 2009-10-07 04:21

Hi Julien,
You shouldn't need any PHP to setup a view with arguments. What is it that you are trying to do?

--
Dave Hansen-Lange
Web Developer
Advomatic LLC
East Asia Office
Hong Kong


Ok, I have a taxonomy tree

jdidelet's picture
jdidelet - Wed, 2009-10-07 04:43

Ok, I have a taxonomy tree like that (for exemple products taxonomy) :
level1
--level1.1
----level1.1.1
level2
...

I use vocabulary index to generate a browsable navigation for my products taxonomy (on URL : my-website.dev/products).

In my pathauto taxonomy term path, I set products/[catpath-raw].

On my my-website.dev/products/level1 page, I want publish a block with all nodes who have level1, level1.1 or level 1.1.1 values(all child values) below the vocabulary browsable index.
If I'm on my-website.dev/products/levle1/level1 .1, I'll publish only nodes with level1.1 or level1.1.1 values. For that, I want to create this block with views.

I parameter this block with "Taxonomy: Term ID (with depth)" argument. But I need to add some php code in "PHP argument code: " to personalize my argument (I want just the last value of my url).

Julien Didelet


Two things come to mind.

dalin's picture
dalin - Wed, 2009-10-07 05:03

Two things come to mind. First arg() returns the internal Drupal path, not an alias, so it might return something like "products/[term_id]". You might instead look at drupal_request_uri() instead:
http://api.drupal.org/api/function/request_uri/6

Secondly a taxonomy argument can be configured in many different ways. It can either accept an ID, or the term name. Make sure you are using the right one given the data that you have.

Also if you aren't using the devel module go install that first. It makes for really easy debugging. Just put a dpm($variable); anywhere you are confused about what the value of something might be.

--
Dave Hansen-Lange
Web Developer
Advomatic LLC
East Asia Office
Hong Kong


Oh yes you're right. I forgot

jdidelet's picture
jdidelet - Wed, 2009-10-07 05:31

Oh yes you're right. I forgot this. arg() doesn't work with alias... It's probably that.

Thanks for your help !
Julien

Julien Didelet