Passing variables between URL

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
glennjamieson
New Member
New Member
Posts: 8
Joined: Fri Mar 06, 2009 12:28 pm

Passing variables between URL

Post by glennjamieson »

Hello,
I am farely new to programming and very new to CMSMS so go easy on me!  I have my own code which I have integrated into templates using the {php} tags.  This code works fine when it is not in CMSMS.  It is for my intranet at work.  I have created 2 pages - staff and staffDetails and I am trying to pass a variable between the staff page and staffDetails page.  The staff page contains the employees and there is a link next to each name to view more information.  This usually pulls the staffID from the database and the persons details are displayed.  I have created staffDetails with staff as its parent.  Here is the code I have used:
Staff Page

This to display list of people with a 'more' link next to every name.

{php}
while ($row = $resultSystems -> fetch_assoc()) {
{/php}

{php}
echo $row['name'];
echo ' More'; {/php}

{php} } {/php}

When I hover over the more link in a browser the correct staffID number is displayed but when I click on it it says Page can not be displayed.  Hope this is clear enough.

Thanks,
Glenn
Aus Butterflies

Re: Passing variables between URL

Post by Aus Butterflies »

Hi.

Where are you actually inserting this bit of code?

You said the template. If that is the case, you should not use bb code. You should instead use proper php tags, such as

Code: Select all

<?php while ($row = $resultSystems -> fetch_assoc()) { ?>
rather than {php} etc..

The method you are showing is only used if you insert php calls into a page you are creating in admin.
glennjamieson
New Member
New Member
Posts: 8
Joined: Fri Mar 06, 2009 12:28 pm

Re: Passing variables between URL

Post by glennjamieson »

Hi, I have just tried a simple code test in the template:



and it doesnt work.  Unless I havent changed a setting or something? Yes I am inserting it into the template.  The strange thing is that the code to bring the list of employees works, it is when I am trying to pass the variable when I get 'page cannot be displayed'.

Thanks
NaN

Re: Passing variables between URL

Post by NaN »

See config.php line 116: $config['use_smarty_php_tags'] = false;
Set this to true and you can use php-Code within your template using {php} ... {/php}.
Or create an UDT where you can just write php-Code (without '').
In your template you can call this UDT with just {your_tag_name}.
glennjamieson
New Member
New Member
Posts: 8
Joined: Fri Mar 06, 2009 12:28 pm

Re: Passing variables between URL

Post by glennjamieson »

Yes i do have use smarty tags set to true.  my only problem is passing the variable in the URL.  I can pull the info from the database fine, but when i try to view any details of the info it doesnt work.
NaN

Re: Passing variables between URL

Post by NaN »

Im no prefessional programmer, but just some ideas:
glennjamieson wrote:
echo ' More'; {/php}
Just watch your URL.
It seems to be that you use the internal pretty-urls, don't you?
So i believe that because of the internal url-rewriting of CMSms core the CMS searches for a page called "staffDetails?staffID=X".
That means the system wants to load "index.php?page=staffDetails?staffID=X"
And this is no valid page alias.
Last edited by NaN on Sun Mar 08, 2009 10:20 pm, edited 1 time in total.
glennjamieson
New Member
New Member
Posts: 8
Joined: Fri Mar 06, 2009 12:28 pm

Re: Passing variables between URL

Post by glennjamieson »

yes you are correct.  I have now set pretty urls to false but this hasnt worked.  i think i know what you are saying, and it sounds correct.  what you are saying is right but is there a way to do what i need to do?

thanks again
NaN

Re: Passing variables between URL

Post by NaN »

how does the link look now?
alby

Re: Passing variables between URL

Post by alby »

My advice:
1. not use php in template but build an UDT for retrieve data from DB (look examples in "share UDT" in wiki)
2. if you have some skills, use CMSMS API for URL generating or use un direct url (index.php?page=alias_of_target&myvar=myval)
3. for retrieve your data in template of target page use the variable {$smarty.get.myvar} (ex: $smarty.get.staffID)

Alby
Last edited by alby on Sun Mar 08, 2009 10:36 pm, edited 1 time in total.
glennjamieson
New Member
New Member
Posts: 8
Joined: Fri Mar 06, 2009 12:28 pm

Re: Passing variables between URL

Post by glennjamieson »

hello.  the third option sounds like something i can do.  can you please give me more detail of how to do this?
thanks
alby

Re: Passing variables between URL

Post by alby »

glennjamieson wrote: hello.  the third option sounds like something i can do.  can you please give me more detail of how to do this?
http://www.smarty.net/manual/en/languag ... smarty.php
you can display all GET variables in smarty with {$smarty.get.myvar}


Alby
glennjamieson
New Member
New Member
Posts: 8
Joined: Fri Mar 06, 2009 12:28 pm

Re: Passing variables between URL

Post by glennjamieson »

Re: you can display all GET variables in smarty with {$smarty.get.myvar}

where exactly do I put this code?  in the actual link?
alby

Re: Passing variables between URL

Post by alby »

glennjamieson wrote: where exactly do I put this code?  in the actual link?
This is for target page (I think your StaffDetail):
alby wrote: 3. for retrieve your data in template of target page use the variable {$smarty.get.myvar} (ex: $smarty.get.staffID)
For Staff page and link follow:
alby wrote: 2. if you have some skills, use CMSMS API for URL generating or use un direct url (index.php?page=alias_of_target&myvar=myval)
Alby
glennjamieson
New Member
New Member
Posts: 8
Joined: Fri Mar 06, 2009 12:28 pm

Re: Passing variables between URL

Post by glennjamieson »

hey alby,
I am sure what you are saying is correct but I cant figure out how to do it.  it is very frustrating.  is there no simple way to pass a variable in cmsms?  what i am trying to do should be quite easy.
alby

Re: Passing variables between URL

Post by alby »

glennjamieson wrote: I am sure what you are saying is correct but I cant figure out how to do it.  it is very frustrating.  is there no simple way to pass a variable in cmsms?  what i am trying to do should be quite easy.
Check the sintax of your link
glennjamieson wrote: echo ' More'; {/php}
Is it correct? Or maybe: More

Alby
Post Reply

Return to “Developers Discussion”