 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
squeak24 Smarty Rookie
Joined: 04 Jul 2012 Posts: 5
|
Posted: Wed Jul 04, 2012 5:41 pm Post subject: {if $smarty.session.security.buddylist == '0' } |
|
|
I am currently working on an open source project that was initially abandoned by the original developer in 2010 when it was still in it's infancy.
I am getting very close to releasing a release canditate. But I am stuck on one thing.
What I want to do is when a user is on someones profile, if they are a "buddy" they see one link, if they are not they see another link.
This is what I have at the moment
| Code: |
{if $smarty.session.security.buddylist == 0 }
<div style="white-space:nowrap;"><a href="index.php?page=compose&recipient={$user.id}" class="btn-view"><span>{lang mkey='send_mail'}</span><em></em></a></div>
{else}
<div style="white-space:nowrap;"><a href="index.php?page=friends&act=F&ref_id={$user.id}&rtnurl=index.php?page=profile" class="btn-view"><span>{lang mkey='addFriend'}</span><em></em></a></div>
{/if}
|
This only shows the add friend link, no matter if they are on the buddy list or not.
I can't actually find referece to the buddylist in the smarty folder, but I am finding that if I change the 0 to other variables it does have an effect on what is displayed.
Any assistance would be appreciated. |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7047 Location: Lincoln Nebraska, USA
|
Posted: Wed Jul 04, 2012 8:38 pm Post subject: |
|
|
maybe something like this:
PHP:
| Code: | | $smarty->assign("is_buddy",$acl->isBuddy()); |
Smarty template:
| Code: | | {if $is_buddy}...{else}...{/if} |
The $acl->isBuddy() I made up, but you get the point. Do the work in PHP to determine if the current user is a buddy or not, and assign a simple boolean value to the template. The template logic is then as simple as possible, and does not intervene with the underlying business logic or data structures (ie. session data.) Then you know the template is looking at one assigned tpl var, and you can concentrate on the PHP logic to deliver the correct boolean flag.
Another popular option is to assign an object to the template, and do something like:
| Code: | | {if $acl->isBuddy()}...{else}...{/if} |
That is up to you and your own design preference. I prefer the former and keep templates separated from PHP logic.
| Quote: | | This only shows the add friend link, no matter if they are on the buddy list or not. |
That means some data the template is looking at is not (always) correct, and it may be easier to manage this logic in PHP, as stated above. It is usually better and easier to manage access to session vars in PHP.
In any event, you need to debug why $smarty.session.security.buddylist, or (which is $_SESSION['security']['buddylist'] in PHP) is not what you expect it to be. |
|
| Back to top |
|
squeak24 Smarty Rookie
Joined: 04 Jul 2012 Posts: 5
|
Posted: Thu Jul 05, 2012 5:50 pm Post subject: |
|
|
I don't want to com acros as being stupid here, although I have used Smarty in the past, I am still not that hot with it.
in the code:
| Code: |
$smarty->assign("is_buddy",$acl->isBuddy());
|
what would acl and isBuddy equivilent to. I would say the acl is the database table.
Any help would be appreciated. |
|
| Back to top |
|
squeak24 Smarty Rookie
Joined: 04 Jul 2012 Posts: 5
|
Posted: Thu Jul 05, 2012 6:30 pm Post subject: |
|
|
OK, I think I am getting there, I have this at the moment:
| Code: |
$t->assign('is_buddy',$fDB->isBuddy('SELECT*FROM ! WHERE userid = ? and act = ?', array( BUDDY_BAN_LIST, $_REQUEST['id'], 'F')));
|
However this is bringing up an error in the edited file
| Quote: |
Fatal error: Call to undefined method FusionDB::isBuddy() in /home/****/public_html/dev/KangaA1/templates/widgets/ProfileUserDefaultPic.php on line 47
|
|
|
| Back to top |
|
squeak24 Smarty Rookie
Joined: 04 Jul 2012 Posts: 5
|
Posted: Thu Jul 05, 2012 9:28 pm Post subject: |
|
|
OK, took a lot of sorting out, but with your help I have it working now.
In the PHP file I have used:
| Code: |
$t->assign('is_buddy', $fDB->getAll('SELECT*FROM ! WHERE userid = ? and act = ?', array( BUDDY_BAN_TABLE, $_REQUEST['id'], 'F')));
|
Then used what you had in the tpl file, and it works.
Thank you for your help! |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|