Page 1 of 1

$params doesn't work...

Posted: Mon Jan 03, 2011 9:01 pm
by cve
Hi everyone, I'm tray to create link in my module with some params through CreateLink form CMSModule class, and I wont to 'catch' my params in target action debug_display() shows nothink beside 'action' param, but in $_GET array all is fine

Re: $params doesn't work...

Posted: Tue Jan 04, 2011 4:55 am
by calguy1000
a) A specific code example would be useful.
b) a better description is necessary
is this a link to a frontend action, or an admin

I can assure you this code works, it's used in hundreds of modules every day.

Re: $params doesn't work...

Posted: Tue Jan 04, 2011 5:08 pm
by cve
I have function, which genereates list (ul, li) end foreach li element contains the link to action 'add_category' with some params, this link in my loop looks like this:

Code: Select all

$html .= "<li>" . $tree[$i]['name'] . "&nbsp;&nbsp;&nbsp;".$this->CreateLink($id, 'add_category', $returnid, '<img src='.$this->GetModuleURLPath().'/images/add.gif />', array('param1'=>'somethink'), null, $onlyhref, $inline, $addttext)."\n";
And, in my action.add_cateogry.php I have this code:

Code: Select all

echo 'Add category';
debug_display($params['param1']);
this code displays only param 'action' => 'add_category', but what about param1 in my link?
When I added $_GET['param1'] to mentioned code:

Code: Select all

echo 'Add category';
//debug_display($params['param1']);
echo $_GET['param1'];
It's shows 'somethink'...

Re: $params doesn't work...

Posted: Tue Jan 04, 2011 5:15 pm
by calguy1000
I'm going to 'assume' that you're using the latest version of CMSMS, and that you are talking about a frontend action and not an action for the admin panel.

In your SetParameters method you probably have something like this:

Code: Select all

$this->RegisterModulePlugin();
$this->RestrictUnknownParameters();
The RestrictUnknownParameters() method tells the system that unless a parameter is 'registered' with the system that it should be stripped from the $params array. (Not having this line can generate a notice on frontend displays).

Therefore for each parameter you will be accepting in a frontend action you should call

Code: Select all

$this->SetParameterType('param_name',CLEAN_xxxx); 
i.e:

Code: Select all

$this->SetParameterType('param1',CLEAN_STRING);

Re: $params doesn't work...

Posted: Tue Jan 04, 2011 5:39 pm
by cve
Doesn't work...
I was added this code:

Code: Select all

        $this->CreateParameter('node_lft', '', $this->Lang('node_lft_help'));
        $this->SetParameterType('node_lft', CLEAN_INT);


        $this->CreateParameter('node_rgt', '', $this->Lang('node_rgt_help'));
        $this->SetParameterType('node_rgt', CLEAN_INT);
but it's still not working...:/

Re: $params doesn't work...

Posted: Tue Jan 04, 2011 6:07 pm
by Wishbone
In your example above you had a parameter called 'param1' in your code... Was this a hypothetical parameter? Or was it a real one, as I don't see it in your CreateParameter call.

Re: $params doesn't work...

Posted: Wed Jan 05, 2011 3:30 am
by cve
Because now I'm using node_lft and node_rgt params... - param1 was mentioned for example...

Re: $params doesn't work...

Posted: Wed Jan 05, 2011 4:16 am
by Wishbone
OK...... In your example, you set some parameter to 'somethink'. However, in your SetParameterType call, you say 'CLEAN_INT' ... 'somethink' isn't an integer.

Re: $params doesn't work...

Posted: Wed Jan 05, 2011 6:33 am
by Wishbone
What exactly does your link look like and what is the value of $id?

Re: $params doesn't work...

Posted: Wed Jan 05, 2011 3:51 pm
by cve
in loop:

Code: Select all

$html .= "<li>" . $tree[$i]['name'] . "&nbsp;&nbsp;&nbsp;".$this->CreateLink($id, 'add_category', $returnid, '<img src='.$this->GetModuleURLPath().'/images/add.gif />', array('node_lft'=>$tree[$i]['lft'], 'node_rgt'=>$tree[$i]['rgt']), null, $onlyhref, $inline, $addttext)."\n";
$id is nothink...:/, should I put to it some value? and early code:

Code: Select all

$this->CreateParameter('node_lft', null, $this->Lang('node_lft_help'));
        $this->SetParameterType('node_lft', CLEAN_INT);


        $this->CreateParameter('node_rgt', null, $this->Lang('node_rgt_help'));
        $this->SetParameterType('node_rgt', CLEAN_INT);
and my action.add_category.php

Code: Select all

<?php
echo 'Add Category';
debug_display($params);

Re: $params doesn't work...

Posted: Wed Jan 05, 2011 4:37 pm
by Wishbone
Did you overwrite $id somewhere? I usually get 'm1' if I only have one instance.

Please post the actual link created, not the PHP code used to post the link. Usually params passed into CreateLink will have the $id prepended to it, so it should look something like &m1node_lft=1

Re: $params doesn't work...

Posted: Wed Jan 05, 2011 5:55 pm
by cve
I don't override $id anywhere and it's looks like you said with prefix m1_node_lft=1etc....

Re: $params doesn't work...

Posted: Wed Jan 05, 2011 6:50 pm
by Wishbone
Sorry, your posts are extremely confusing.

* You show detailed code using a parameter called 'param1', and later tell us that this is an example, and not the real one.
* It looks like you are passing strings in your example, but are using CLEAN_INT. It's hard to tell what is an example, and what is real.
* You say that $id is 'somethink', but later say it's 'm1'. There's no way that $_GET['node_lft'] will work when your link contains &m1node_lft=1
* You still haven't posted what the actual link looks like.

Please spend some time formulating your question, posting code, and verify that your information is correct. Half of the time I figure out the answer while posting, just because I spent some time making sure that my post is accurate and consistent with itself.

Please don't post 'examples'... post the actual code. Anything other than this is wasting our time.