CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Getting GET info in any god damn view
Pages: [1]

Author Topic: Getting GET info in any god damn view  (Read 947 times)

JohnathanPaulus

  • Guest
Getting GET info in any god damn view
September 13, 2010, 03:44:08 pm
I am new to Civicrm. I find it a powerful, yet scarily unmanageable system.

My problem is following: I have a contribution page that I want to show differently to members and non members. To be precise, I don't want non-members to see it at all. The ACL and group setting that I can handle only let me manage ALL or NONE in terms of contributions and I have another page that I want to show to all anonymous users.

So. I want a fast, non-complicated fix. I want a hack or pretty much anything that works without having to extend the civicrm, as I am the biggest of novices to Smarty (even though I'm a professional in Zend) and to be honest, I feel very very constrained by it.

As it turns out, I am so much of a buffoon in Smarty that I can't even assign $_GET['id'] to a value to pick out the id of the specific little contribution page that I have.

I have tried all possible combinations of assign, print_r, {php} code (that doesn't set variables outside the php code - wth is going on).

Please do help me in this or I will never ever manage to get to the next step of learning this thing. Oh, and sorry if I posted this in the wrong area, please move post around as you see fit.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Getting GET info in any god damn view
September 13, 2010, 04:23:42 pm
If you haven't at least skimmed to "Extending CiviCRM" section of the online book, I think that'll help make things a bit more "manageable":
http://en.flossmanuals.net/CiviCRM/DevelopIntro

You're right that there's no way currently to control access to different contribution pages based on Drupal role or Civi's built-in ACL's. One approach to this is to implement the buildForm hook (in a separate custom Drupal module). The hook can simply check the status of the user session (i.e. authenticated vs. anonymous user, CiviMember member, whatever you're trying to branch on) - and then redirect if necessary to an alternate page.

Hooks are introduced in the book section above and documented in detail here:

http://wiki.civicrm.org/confluence/display/CRMDOC32/CiviCRM+hook+specification

You might also be able to add some jscript to the online contribution form to do the redirect. You can get any URL query string parameter using the $smarty reserved variables. For example {$smarty.get.id} will return the id= query string param for your contribution pages.

BTW, see the "tip" about using smartyDebug on this page for info on how to see what application variables are available to a smarty template:

http://en.flossmanuals.net/CiviCRM/DevelopTemplates

Best to jump on IRC if you need more guidance - #civicrm on freenode.net.
Protect your investment in CiviCRM by  becoming a Member!

JohnathanPaulus

  • Guest
Re: Getting GET info in any god damn view
September 14, 2010, 02:51:23 am
Thank you very much for the answer, it was genuinely helpful, especially the last little part in the last link (to get the user ID) and I finally got it to work as supposed. Millions of thanks, as I've lost over eight hours for that little little thing. For anyone that lands here through google, here is my working little hack:

Code: [Select]
{if ($smarty.get.id == 6) and $session->get('userID') < 1}
{php}
header('Location: http://www.yourdomain.com/');
{/php}
{/if}

In general, I am very very surprised to how barred in I feel in Smarty. I cannot assign variables as I want, I cannot use php-native functions as I want. It will take me a long time before I get used to Smarty in general and civicrm in particular. I can understand that some people might find the logical layout difficult, but I'm working with MVC for a living, how can it be so chaotic? Why are there functions in the views? Shouldn't that have been handled in the controller, or at least through general helpers to avoid duplicating code?

Why is extending the framework so non-linear? You add terms like user/2/ if you want to have a special setting for user 2, but what if I have a really specific wish and run out of chars while declaring the arguments in the name? And guys, why is every page littered with JavaScript? And I've seen JS redirects - what if I shut off js and go to precisely any of those pages?

I have so many questions to be able to understand this framework better. I'm sorry, after Zend, this just doesn't fit in my head... But then again, I can't let Smarty win :)
« Last Edit: September 14, 2010, 02:53:32 am by JohnathanPaulus »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Getting GET info in any god damn view
September 14, 2010, 04:47:10 am
Quote from: JohnathanPaulus on September 14, 2010, 02:51:23 am

In general, I am very very surprised to how barred in I feel in Smarty. I cannot assign variables as I want, I cannot use php-native functions as I want. It will take me a long time before I get used to Smarty in general and civicrm in particular.

Yes you can assign variables, there is an {assign
...and yes, that's different than PHP/jquery/whatever you are used to. Skim the smarty site should help you clarifying how to do things the smarty way (don't confuse it with how to do things the smart way, might be different ;)

Quote from: JohnathanPaulus on September 14, 2010, 02:51:23 am

 I can understand that some people might find the logical layout difficult, but I'm working with MVC for a living, how can it be so chaotic? Why are there functions in the views? Shouldn't that have been handled in the controller, or at least through general helpers to avoid duplicating code?

And I'm sure you will stumble into weird, gross, hairy, smelly bits here and there. So far, can probably think of only one big project that doesn't have these visible wards. And that's not one written in PHP.

On the good news, that's open source, open to contributions and that's getting in the right direction IMO.

Quote from: JohnathanPaulus on September 14, 2010, 02:51:23 am

Why is extending the framework so non-linear? You add terms like user/2/ if you want to have a special setting for user 2, but what if I have a really specific wish and run out of chars while declaring the arguments in the name? And guys, why is every page littered with JavaScript? And I've seen JS redirects - what if I shut off js and go to precisely any of those pages?

Because it's used on the page, and serve a purpose ? Yes, quite a few js libraries loaded, even in pages that don't necessary need them, but easier to manage, and that's cached so no big deal.

As for the JS redirect, Dave suggested that because you asked for a quick hack, and we all know it won't win any beauty contest

Quote from: JohnathanPaulus on September 14, 2010, 02:51:23 am

I have so many questions to be able to understand this framework better. I'm sorry, after Zend, this just doesn't fit in my head... But then again, I can't let Smarty win :)

Beside the developer chapter on the book that you should read, go to http://civicrm.org/architecture (especially the oldest posts, that explain the logic of what is called when).

And yes, like any new big software, that's different than (insert your favourite framework). And everytime, that's a big f**king pain to wrap your head around new conventions, architecture, libraries helpers and all that jazz.

Good luck

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

JohnathanPaulus

  • Guest
Re: Getting GET info in any god damn view
September 14, 2010, 05:58:15 am
Well, thanks I guess. I'll surely be back for more adorable novice advice shortly.

Quote
Yes you can assign variables, there is an {assign
...and yes, that's different than PHP/jquery/whatever you are used to. Skim the smarty site should help you clarifying how to do things the smarty way (don't confuse it with how to do things the smart way, might be different
Well, this is the general kind of mindset with smarty that I have the biggest problems with. Every other framework I have encountered is building upon a language, extending it, merging it, improving it etc. Somehow, Smarty has decided to use an interesting form of replace instead. I'm not saying all of it is bad, many of the $variable|/*set looping bgcolors here*/ things are generally nice, but it feels like all the basic features have been removed. If I have to go through assign (which, I seriously believe is the wrong way of doing it), how can I get through such simple things as +=, .= etc? Why can't I access $_GET, $_SESSION, $_SERVER or $_COOKIE directly? If I reverse an array, do I have to reassign it to a variable? It feels like I'm on a white tie ball and custom dictates that people have to stand up and sit down everytime they touch a fork.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Getting GET info in any god damn view

This forum was archived on 2017-11-26.