$params doesn't work...

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

$params doesn't work...

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: $params doesn't work...

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Re: $params doesn't work...

Post 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'...
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: $params doesn't work...

Post 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);
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Re: $params doesn't work...

Post 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...:/
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: $params doesn't work...

Post 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.
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Re: $params doesn't work...

Post by cve »

Because now I'm using node_lft and node_rgt params... - param1 was mentioned for example...
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: $params doesn't work...

Post 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.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: $params doesn't work...

Post by Wishbone »

What exactly does your link look like and what is the value of $id?
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Re: $params doesn't work...

Post 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);
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: $params doesn't work...

Post 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
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Re: $params doesn't work...

Post by cve »

I don't override $id anywhere and it's looks like you said with prefix m1_node_lft=1etc....
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: $params doesn't work...

Post 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.
Post Reply

Return to “Developers Discussion”