Goldeneye Posted December 7, 2008 Share Posted December 7, 2008 I am working on a category-system class for my site. Everything in the script itself appears to work fine but when I try to use it in my templating-system class, it doesn't work like it should. Here's how I am doing it (which doesn't work): <?php if(isset($_POST['action'])) echo $category->set(0); $layout->page('foo/bar/tmp.html'); $mainb = '<form action="foobar.php" method="post">'.$category->show(0, $_SESSION['auth']).'<input type="submit" name="action" value="Action" class="button"></form>' $layout->output(array('tpl.sideb' => $sideb, 'tpl.mainb' => $mainb)); ?> But if it's done this way, it works just fine. Though, this way, I can't use my templating system. <?php if(isset($_POST['action'])) echo $category->set(0); echo '<form action="foobar.php" method="post">'; echo $category->show(0, $_SESSION['auth']); echo '<input type="submit" name="action" value="Action" class="button"></form>'; ?> I don't suppose there's any other alternative method here, is there? Here is my template-system class: <?php class template { var $page; //page() retrieves the template file given a directory/file-path function page($template){ if(file_exists($template)) $this->page = join('', file($template)); else die('Template file "'.$template.'" could not be found.'); } function parse($file){ ob_start(); include $file; $buffer = ob_get_contents(); ob_end_clean(); return $buffer; } //output() replaces the corresponding tags (array-keys) with their array-values function output($tags = array()){ if(sizeof($tags) > 0){ foreach($tags as $tag => $data){ $data = (file_exists($data)) ? $this->parse($data) : $data; $tag = preg_quote($tag); $this->page = preg_replace('/<!--' . $tag . '-->/i', $data, $this->page); } } else return 'Error: Uncorresponding tags'; echo $this->page; } } $layout = new template; ?> And here's my category-system class <?php class categories { //check() and rights() simply keep and checked boxes checked upon page-view or form-procession function check($category, $code){ if (($category & $code) != 0) return ' CHECKED '; else return ''; } function rights($rights, $r){ if ($rights & $r) return ' CHECKED '; else return ''; } //gen() returns an array of categories corresponding to the $type variable (a number) function gen($type, $loop=true){ //TYPES: 0 = user-permissions, if($type==0) $categories = array(1 => 'View Profiles', 2 => 'Edit Profiles', 4 => 'Edit Authorizations', 8 => 'View Users\' History', 16 => 'Site-Maintenance'); if($loop){ $categorylist = array(); foreach($categories as $key => $val) $categorylist[] = array($val, $key); return $categorylist; } else return $categories; } //show() displays the categories in a table (to be used in a form) function show($ctype, $dbarray=''){ $categories = $this->gen($ctype); echo '<table border="0" width="500px">'; for($i = 0; $i < count($categories); ++$i){ if($ctype==0) $checked = $this->rights($dbarray, $categories[$i][1]); else $checked = $this->check($dbarray, $categories[$i][1]); if($i%2==0) echo '<tr><td><input type="checkbox" ' . $checked . ' name="c' . $categories[$i][1] . '" id="c' . $categories[$i][1] . '">' . '<label for="c' . $categories[$i][1] . '"> ' . $categories[$i][0] . '</label></td>'; else echo '<td><input type="checkbox" ' . $checked . ' name="c' . $categories[$i][1] . '" id="c' . $categories[$i][1] . '">' . '<label for="c' . $categories[$i][1] . '"> ' . $categories[$i][0] . '</label></td></tr>'; } if($i%2!=0) echo '</tr>'; echo '</table>'; } //set() returns all the checked box values in the form of an integer function set($ctype){ $catlist=$this->gen($ctype); $count = count($catlist); $cat=0; for($i=0; $i < $count; ++$i){ if(isset($_POST['c' . $catlist[$i][1]])) $cat|=$catlist[$i][1]; } return $cat; } } $category = new categories; ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2008 Share Posted December 7, 2008 There is a semi-colon ; missing on the end of the - $mainb = .... line of code that causes a fatal parse error and prevents the first set of code from executing. Are you developing and debugging php on a system with error_reporting set to E_ALL and display_errors set to ON to get php to help you with problems like this? Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted December 7, 2008 Author Share Posted December 7, 2008 That was just a typo, sorry, but yes a missing semi-colon would've been picked up as an error, and I do have error_reporting(E_ALL); enabled. Though, I still get no errors. All that $category->set() returns is '0' even if all the checkboxes are checked. Quote Link to comment 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.