amclean Posted November 16, 2008 Share Posted November 16, 2008 I'm adapting a "page class" that provides the interface and menu across a site. For this particular project, there will be multiple user types which will have different menu options. I'm trying to integrate these variations in the "page class" include file. Problem is, i get php validation errors because it's expecting only functions, not "if/else" statements. Ultimately what i need is for the "row2buttons" array to be set by a "usertype" condition, but i can't figure out how. function Display() { echo "<html>\n<head>\n"; $this -> DisplayTitle(); echo "</head>\n<body>\n"; $this -> DisplayHeader(); $this -> DisplayMenu($this->buttons); $this -> DisplayMenu($this->row2buttons); echo $this->content; $this -> DisplayFooter(); echo "</body>\n</html>\n"; } If there's any details I've failed to mention please let me know. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/132951-solved-conditions-inside-of-a-class-function/ Share on other sites More sharing options...
veridicus Posted November 16, 2008 Share Posted November 16, 2008 Sounds like you have two options. Either pass the usertype or row2buttons array into the Display function, or have the Display function call something else to determine the usertype or row2buttons values. Quote Link to comment https://forums.phpfreaks.com/topic/132951-solved-conditions-inside-of-a-class-function/#findComment-691369 Share on other sites More sharing options...
amclean Posted November 16, 2008 Author Share Posted November 16, 2008 I thought of that, too, but I'm having trouble with that. I don't wish to specify it on each page the user visits so that's out. And if i put an if/else clause on the class include file, there's 2 places i can try to put it - inside the class, or outside the class. Inside, it complains that the if/else isn't a function and so doesn't belong inside the class. Outside, the "DisplayMenu($this->row2buttons);" doesn't seem to be able to pull in an array at all. It complains that it's not an array. Quote Link to comment https://forums.phpfreaks.com/topic/132951-solved-conditions-inside-of-a-class-function/#findComment-691525 Share on other sites More sharing options...
amclean Posted November 16, 2008 Author Share Posted November 16, 2008 Alright well thanks anyway everyone but I'm about to answer my own question. I was putting it in the wrong place inside the function. Fixed as follows: function Display() { if ($usertype==1) { $row2buttons = array( 'A' => 'a.php', 'B' => 'b.php'); } elseif ($usertype==2) { $row2buttons = array( 'C' => 'c.php', 'd' => 'd.php'); } echo "<html>\n<head>\n"; $this -> DisplayTitle(); echo "</head>\n<body>\n"; $this -> DisplayHeader(); $this -> DisplayMenu($this->buttons); $this -> DisplayMenu($this->row2buttons); echo $this->content; $this -> DisplayFooter(); echo "</body>\n</html>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/132951-solved-conditions-inside-of-a-class-function/#findComment-691625 Share on other sites More sharing options...
trq Posted November 16, 2008 Share Posted November 16, 2008 Cool, can you hit the 'TOPIC SOLVED' button now (bottom left)? Quote Link to comment https://forums.phpfreaks.com/topic/132951-solved-conditions-inside-of-a-class-function/#findComment-691628 Share on other sites More sharing options...
amclean Posted November 16, 2008 Author Share Posted November 16, 2008 Just thought I'd drop a quick message that "veridicus" was indeed correct about the choices, my mistake was putting the condition in the wrong part of the function. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/132951-solved-conditions-inside-of-a-class-function/#findComment-691676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.