Page 1 of 2

Passing variables between URL

Posted: Fri Mar 06, 2009 2:22 pm
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

Re: Passing variables between URL

Posted: Sat Mar 07, 2009 10:31 pm
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.

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 9:08 pm
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

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 9:53 pm
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}.

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 10:07 pm
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.

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 10:16 pm
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.

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 10:29 pm
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

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 10:31 pm
by NaN
how does the link look now?

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 10:34 pm
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

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 10:44 pm
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

Re: Passing variables between URL

Posted: Sun Mar 08, 2009 10:54 pm
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

Re: Passing variables between URL

Posted: Mon Mar 09, 2009 1:41 pm
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?

Re: Passing variables between URL

Posted: Mon Mar 09, 2009 1:54 pm
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

Re: Passing variables between URL

Posted: Mon Mar 09, 2009 2:16 pm
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.

Re: Passing variables between URL

Posted: Mon Mar 09, 2009 2:30 pm
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