PHP - Help With Isset And $_get Methods
Hi, I'm new to php and am attempting to build a site where the navigation and content is built with query functions.
My current tables in my database are Categories, Products, and Variation. So a person chooses a category -> then a product -> then a product page shows variations for that product. The problem I am currently having is after when a person selects a section the previous section selected is reset. So lets a person selects a category the product list is shown, but when a person selects a product, the category is no longer selected in the navigation. Or if someone selects product and sees all the variations, if he selects a variation the product ID is reset. I've tried to comb through the internet for some type of solution. I came across concatenating URL encode, but am not sure if this is the correct solution. I tried concatenating one of my urls with Code: [Select] "<a href=\"product_detail.php?cat=" . urlencode($sel_cat["id"]) . '&' . "product=" . urlencode($sel_product['id']) . '&' . "var=" . urlencode($var["id"]) . "\" its a bit of a stab in the dark. My $_GET function is Code: [Select] function find_selected_product() { global $sel_cat; global $sel_product; global $sel_var; if (isset($_GET['cat'])) { $sel_cat = get_cat_by_id($_GET['cat']); } elseif (isset($_GET['product'])) { $sel_cat = NULL; $sel_product = get_product_by_id($_GET['product']); } elseif (isset($_GET['product'])) { $sel_product = get_product_by_id($_GET['product']); $sel_var = get_default_var($sel_product['id']); } elseif (isset($_GET['var'])) { $sel_product = NULL; //test $sel_var = get_variation_by_id($_GET['var']); } else { $sel_cat = NULL; $sel_product = NULL; $sel_var = NULL; } } My navigation code is Code: [Select] function public_navigation($sel_cat, $public = true) { $output = "<td class=\"c1\"><div class=\"sidenav\"><ul>"; $cat_set = get_all_cats($public); while ($cat = mysql_fetch_array($cat_set)) { $output .= "<li>"; if ($cat["id"] == $sel_cat['id']) { $output .= "<a class=\"current\""; } $output .= "<a href=\"index.php?cat=" . urlencode($cat["id"]) . "\">{$cat["cat_name"]}</a></li>"; } $output .= "</ul>"; return $output; } My product is divided into gender and is written like Code: [Select] function cat_content_ladies($sel_cat, $sel_product, $female = true) { $output = "<ul class=\"regions\">"; $cat_set = get_all_cats($female); while ($cat = mysql_fetch_array($cat_set)) { if ($cat["id"] == $sel_cat['id']) { $product_set = get_products_for_female($cat["id"], $female); $output .= "<tr>"; while ($product = mysql_fetch_array($product_set)) { if ($cat["id"] == $sel_cat['id']) { $output .= "<tr>"; $output .= "<div class=\"pre\"><a href=\"product_detail.php?product=" . urlencode($product["id"]) . "\"></li>"; $output .= "<img src=\"{$product["img_src"]}\" height=\"121\" width=\"121\">"; $output .= "<div>{$product["prod_name"]}</a></div>"; } } $output .= "</tr>"; } } return $output; } My variation table is set up in thumb nails and is written in this function Code: [Select] function show_thumb($sel_product, $sel_var, $public = true) { $output = "<ul class=\"subjects\">"; $product_set = get_all_products($public); while ($product = mysql_fetch_array($product_set)) { $output .= "<li"; if ($product["id"] == $sel_product['id']) { $output .= " class=\"selected\""; } //$output .= "><a href=\"product_detail.php?product=" . urlencode($product["id"]) . //"\">{$product["id"]}</a></li>"; if ($product["id"] == $sel_product['id']) { $var_set = get_variations_for_product($product["id"], $public); $output .= "<ul class=\"pages\">"; while ($var = mysql_fetch_array($var_set)) { $output .= "<li"; if ($var["id"] == $sel_var['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"product_detail.php?var=" . urlencode($var["id"]) . "\">{$var["id"]}</a></li>"; } $output .= "</ul>"; } } $output .= "</ul>"; return $output; } any light on this subject would be greatly appreciated. Similar TutorialsA few months ago, and a good amount of time before that, I had people telling me to use isset() instead of performing to see if the variable is empty, such as: !$_GET[''] I know the differences in the function and what they do, but when could isset() be used in a situation where it's better/more efficient then: !$_GET[''] I do use isset(), though. I am having problems with my $_GET. When a user chooses an Article from "article_index.php", they click on a hyperlink, e.g. Code: [Select] <a href="<?php echo BASE_URL; ?>articles/postage-meters-can-save-you-money"> This triggers my Mod_Rewrite... Code: [Select] RewriteEngine on #PRETTY: articles/postage-meters-can-save-you-money #UGLY: article.php?slug=postage-meters-can-save-you-money RewriteRule articles/([a-zA-Z0-9_-]+)$ article.php?slug=$1 Which should take them to "article.php?slug=postage-meters-can-save-you-money" and then this code is supposed to grab the "slug" and retrieve the Article... Code: [Select] // Attempt to Retrieve Article. if (isset($_GET['slug'])){ // Slug found in URL. // Set Slug. $slug = $_GET['slug']; That part is working fine, however, if I go into the Address Bar and delete out the slug, so my URL looks like this... Code: [Select] www.MySite.com/articles/"> I would expect the ELSE part of the above code to kick in... Code: [Select] }else{ // Slug not found in URL. header("Location: " . BASE_URL . "index.php"); }//End of ATTEMPT TO RETRIEVE ARTICLE Unfortunately I am just getting this error... Quote Not Found The requested URL /articles/ was not found on this server. Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2 Server at local.debbie Port 80 Why is my ELSE not detecting that there is no slug?? Debbie Hi I have written a simple bit of code, i used to code php a little and have just decided to start coding php again but for the life of me can't work out why this isn't working, so if someone could help this would be great. address www.mysite.co.uk/index.php?vid=video2 <php if (isset($_GET['vid'])){ $video=$_GET['vid']; }else{ $video="video1"; } when i echo $video i only get video=1 I am trying to do isset($_GET but I have a bizarre problem come up. I am using "id" as one of my fields but when I try to use it in the code it says it is not recognised. However I use this field quite widely. The code its coming up with is "Undefined variable: id" but I cant see why it has a problem with id. My code is: <?php if(isset($_GET['id'])){ $sql = mysql_query("SELECT * FROM productfeed WHERE id='$id' LIMIT 1"); } { while($row = mysql_fetch_array($sql)) $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>&#163; $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>"; } ?> soory guys .. actually i am trying to add pagination in script.. but its not pagging.
but when i tried without isset($_get the code worked fine and then i tried to doing with isset($_get for a perticular cat
but its not working. can someone see my code and tell me whats worng i have done.
<!DOCTYPE HTML> <html> <head> </head> <body> <?php // include database connection include 'libs/db_connect.php'; // page is the current page, if there's nothing set, default is page 1 $page = isset($_GET['page']) ? $_GET['page'] : 1; // set records or rows of data per page $recordsPerPage = 1; // calculate for the query LIMIT clause $fromRecordNum = ($recordsPerPage * $page) - $recordsPerPage; // select all data $query = "SELECT * FROM posts ORDER BY post_id desc LIMIT {$fromRecordNum}, {$recordsPerPage}"; /* page and its LIMIT clause looks like: 1 = 0, 5 2 = 5,10 3 = 10,15 4 = 15, 20 5 = 20, 25 */ $stmt = $con->prepare( $query ); $stmt->execute(); //this is how to get number of rows returned $num = $stmt->rowCount(); //check if more than 0 record found if($num>0){ $cat=1; if(isset($_GET['cat'])){ $cat_id = $_GET['cat']; $get_posts = "select * from posts where category_id = '$cat_id'"; $run_posts = mysql_query($get_posts); while($row_posts = mysql_fetch_array($run_posts)){ $post_id = $row_posts['post_id']; $post_title = $row_posts['post_title']; $post_date = $row_posts['post_date']; $post_author = $row_posts['post_author']; $post_image = $row_posts['image']; $post_content = substr($row_posts['post_content'],0,80); echo " <div class='post_area'> <h4> <a href = 'details.php?post=$post_id'>$post_title</a> </h4> <div class='date'><div id='com'> Date</div>$post_date</div><span style='font-size:12px'><i style='color:grey;font-size:10px'>Posted By</i> </b>$post_author</span> <content><img src = '123dondadatest/news_images/$post_image' width = '100' height='100'/> <div>$post_content <br/><a id='rmlink' href = 'details.php?post=$post_id'> Read More...</a></div><br /><br/><br/><br/> </div> "; } } // *************** <PAGING_SECTION> *************** echo "<div id='paging'>"; // ***** for 'first' and 'previous' pages if($page>1){ // ********** show the first page echo "<a href='" . $_SERVER['PHP_SELF'] . "' title='Go to the first page.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> << </span>"; echo "</a>"; // ********** show the previous page $prev_page = $page - 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$prev_page}' title='Previous page is {$prev_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> < </span>"; echo "</a>"; } // ********** show the number paging // find out total pages $query = "SELECT COUNT(*) as total_rows FROM posts"; $stmt = $con->prepare( $query ); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $total_rows = $row['total_rows']; $total_pages = ceil($total_rows / $recordsPerPage); // range of num links to show $range = 2; // display links to 'range of pages' around 'current page' $initial_num = $page - $range; $condition_limit_num = ($page + $range) + 1; for ($x=$initial_num; $x<$condition_limit_num; $x++) { // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages' if (($x > 0) && ($x <= $total_pages)) { // current page if ($x == $page) { echo "<span class='customBtn' style='background:red;'>$x</span>"; } // not current page else { echo " <a href='{$_SERVER['PHP_SELF']}?page=$x' class='customBtn'>$x</a> "; } } } // ***** for 'next' and 'last' pages if($page<$total_pages){ // ********** show the next page $next_page = $page + 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$next_page}' title='Next page is {$next_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> > </span>"; echo "</a>"; // ********** show the last page echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$total_pages}' title='Last page is {$total_pages}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> >> </span>"; echo "</a>"; } echo "</div>"; // ***** allow user to enter page number echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='GET'>"; echo "Go to page: "; echo "<input type='text' name='page' size='1' />"; echo "<input type='submit' value='Go' class='customBtn' />"; echo "</form>"; // *************** </PAGING_SECTION> *************** } // tell the user if no records were found else{ echo "<div class='noneFound'>No records found.</div>"; } ?> </body> </html> Well the title may seem a bit confusing, but heres an example: Code: [Select] <?php class User{ public $uid; public $username; protected $password; protected $email; public $usergroup; public $profile; public function __construct($id){ // constructor code inside } public function getemail(){ return $this->email; } public function getusergroup(){ return $this->usergroup; } public function getprofile(){ $this->profile = new UserProfile($this->uid); } } class UserProfile(){ protected $avatar; protected $bio; protected $gender; protected $favcolor; public function __construct($id){ // constructor code inside } public function formatavatar(){ // avatar formatting code inside } public function formatusername(){ // format username? } } ?> As you can see, the User class(an outer class) has a property called Profile, which can be instantiated as a UserProfile object(an inner class). The two objects have distinct functionalities, but there are times when the UserProfile object needs to access property and methods from the user object. I know its easy for outer class to access methods from inner class by using the single arrow access operator twice, but how about the other way around? Lets say from the above example the userprofile can format the username displayed to the screen by adding a sun to the left of the username if the usergroup is admin, a moon if the usergroup is mod, and nothing if its just a member. The usergroup property is stored in the outer class, and can be accessed with this $user->getusergroup() method only. I know I can always do the hard way by passing a user object to the method's argument, but is there an easier way for the inner class UserProfile to access properties/methods for outerclass User? If so, how can I achieve that? hey guys im wdondering if there's a magic method which works like
__GET()but allows you to put a parameter in...thank you <?php class test { public function run() { $this->object->('string'); // __get with parameter? } public function __get($value) { return $this->{$value} } } ?> what are magic methods? when do we need to use magic methods? what are the advantages of using magic methods? thanks in advanced. I don't know if this belongs here; sorry if it doesn't. I'm using a method=get on a form as I need to pass information through a URL once the form has been submitted. But I also need to INSERT some data from that form to multiple tables. - How can I stop the GET from passing my other variables into the URL? - How do I make the form submit to itself? I need to use the 'index.php?p=checkout' as this matches with a switch statement, which matches to the checkout page. The function PHP_SELF will just refresh to the index.php page, which will not have any of this checkout's page validation. Here's my code: Code: [Select] <h2>Please enter your details</h2> <h3>All fields required</h3> <div id="checkout"> <?php if (isset($_GET['checkout'])){ require_once ('./includes/connectvars.php'); $title = $_GET['title']; $fname = $_GET['fname']; $sname = $_GET['sname']; $ctype = $_GET['ctype']; $cnumber = md5($_GET['cnumber']); $syear = $_GET['smonth'] . $_GET['syear']; $fyear = $_GET['fmonth'] . $_GET['fyear']; $service = $_GET['cardAuth']; $amount = $_REQUEST[$total]; $msg = rand(1000,9999); $api = 'd41d8cd98f00b204e9800998ecf8427e'; $b_house = $_GET['b_house']; $b_postcode = $_GET['b_postcode']; $b_city = $_GET['b_city']; $b_country = $_GET['b_country']; $d_house = $_GET['d_house']; $d_postcode = $_GET['d_postcode']; $d_city = $_GET['d_city']; $d_country = $_GET['d_country']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "INSERT INTO customer (cust_id, first_name, last_name) VALUES ('', '$fname', '$sname') "; $query = "INSERT INTO bill (cust_id) VALUES ('') "; $query = "INSERT INTO deliver (cust_id) VALUES ('') "; mysqli_query($dbc, $query); } //.'service='.$service.'msg_id='.$msg.'num_md5='.$cnumber.'amount='.$amount.'currency=GBP'.'api_key='.$api. ?> <form method="get" action="index.php?p=checkout"> <table> <tr> <td><input type="hidden" name="cardAuth" /></td> </tr> <tr> <td> Title: </td> <td> <select name="title" value="<?php if (!empty($title)) echo $title; ?>" > <option></option> <option>Mr</option> <option>Sir</option> <option>Ms</option> <option>Miss</option> <option>Mrs</option> </select> </td> </tr> <tr> <td> First Name: </td> <td> <input type="text" name="fname" value="<?php if (!empty($fname)) echo $fname; ?>"/> </td> </tr> <tr> <td> Surname: </td> <td> <input type="text" name="sname" value="<?php if (!empty($sname)) echo $sname; ?>"/> </td> </tr> <tr> <td> </td> </tr> <tr> <td> Card Type: </td> <td> <select name="ctype" value="<?php if (!empty($ctype)) echo $ctype; ?>"> <option>mastercard</option> <option>visa</option> <option>amex</option> <option>solo</option> <option>maestro</option> <option>jcb</option> <option>diners</option> </select> </td> </tr> <tr> <td> Card Number: </td> <td> <input type="text" name="cnumber" value="<?php if (!empty($cnumber)) echo $cnumber; ?>"/> </td> </tr> <tr> <td> Valid From: </td> <td> <select name="smonth" value="<?php if (!empty($smonth)) echo $smonth; ?>"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select> <select name="syear" value="<?php if (!empty($syear)) echo $syear; ?>"> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> </select> </td> </tr> <tr> <td> Expires End: </td> <td> <select name="fmonth" value="<?php if (!empty($fmonth)) echo $fmonth; ?>"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select> <select name="fyear" value="<?php if (!empty($fyear)) echo $fyear; ?>"> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> </select> </td> </tr> <tr> <td><h4>Billing Address</h4></td> </tr> <tr> <td> House Name/ Number: </td> <td> <input type="text" name="b_house" /> </td> </tr> <tr> <td> Postcode </td> <td> <input type="text" name="b_postcode" /> </td> </tr> <tr> <td> City: </td> <td> <input type="text" name="b_city" /> </td> </tr> <tr> <td> Country: </td> <td> <input type="text" name="b_country" /> </td> </tr> <tr> <td><h4>Delivery Address</h4></td> </tr> <tr> <td> House Name/ Number: </td> <td> <input type="text" name="d_house" /> </td> </tr> <tr> <td> Postcode </td> <td> <input type="text" name="d_postcode" /> </td> </tr> <tr> <td> City: </td> <td> <input type="text" name="d_city" /> </td> </tr> <tr> <td> Country: </td> <td> <input type="text" name="d_country" /> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="checkout" value="Checkout"/> </td> </tr> </table> </form> </div> Is there any way to produce a custom magic method? Let's say when I try to get an attribute that doesn't have any value, a method gets called that gives that attribute a value. So I want a method to be triggered when I try to get a value from an attribute that doesn't have any value. I am trying to run the function "age", using the last line, I thought that is how I could to access that method, but that doesn't work. Code: [Select] <?php require_once '../phpLive/phpLive.php'; $live->myClass = (object)array( "name" => "Billy Bob Joe", "age" => function($dob){ // Run some code } ); echo $live->myClass->age("1986-07-22"); ?> I get the following error when trying to do that. Quote Fatal error: Call to undefined method stdClass::age() in /xxx/new.plugin.php on line 9 Any Ideas how I can access that method? Thanks! Hi PhpFreaks, I have a method that I need to be initialised dynamically and I am not sure if the code below will work I have been able to workout if the method exists but I have not found a way to it get to return the array. Has anyone go any ideas? The error I get is: Catchable fatal error: Object of class Forms could not be converted to string Code: [Select] public function setMethodForms($methodName){ echo $methodName." and does it exist ". (int)method_exists($this->formsObj, $methodName); //test to see if the method exists if ((int)method_exists($this->formsObj, $methodName) == 1){ //if it does execute //print_r ($this->formsObj->projects()); //test to see if object works $return call_user_func($this->formsObj."->".$methodName."()"); } return $return; } I have two classes were one extends the other but they both have magic methods __get __call and __set but when trying to call a magic method it conflicts one with the other as you can imagaine...is there a way of getting around this ie. name spaces
or do I simply have to rewrite my classes
thank you
I have a class that has the __get and __set magic methods defined. The idea is to use those to communicate with the __get and __set methods in a database table object which is a protected attribute of this class. Then I can quickly build out models without having to bother with method definitions aside from those that need modifications made to the data before saving. The problem is, they don't seem to be doing anything. I get an undefined function error the first time I call getVarx(). I don't actually have any of the attributes I'm trying to get and set defined in the object, but I thought that was the point of these magic methods. Am I missing something here? Thanks, Brandon hello, i have been following the php.net oop manual but im having a little trouble understanding something. on this page in the manual: http://uk3.php.net/manual/en/language.oop5.basic.php it shows this code and if i seperate it out i cant get it to echo the results i want. what am i doing wrong? i have added a little extra code . class Bear Code: [Select] class Bear { // define properties public $name; public $weight; public $age; public $sex; public $colour; // constructor public function __construct() { $this->name = "winny the poo"; $this->weight = 100; $this->age = 0; $this->sex = "male"; $this->colour = "brown"; } // define methods public function eat($units) { echo $this->name." is eating ".$units." units of food... <br/>"; $this->weight += $units; } public function run() { echo $this->name." is running... <br/>"; } public function kill() { echo $this->name." is killing prey... <br/>"; } public function sleep() { echo $this->name." is sleeping... <br/>"; } } class PolarBear Code: [Select] class PolarBear extends Bear { // constructor public function __construct() { parent::__construct(); $this->colour = "white"; $this->weight = 600; } function polarbar() { // Note: the next line will issue a warning if E_STRICT is enabled. Bear::bear(); } // define methods public function swim() { echo $this->name." is swimming... "; } } now if i try to get back the results i have trouble. this is fine Code: [Select] $bear = new Bear(); $bear->eat($units); $bear->eat(); $bear->run(); $bear->kill(); $bear->sleep(); that echos back Quote //THE BEAR winny the poo is eating 5 units of food... winny the poo is eating units of food... winny the poo is running... winny the poo is killing prey... winny the poo is sleeping... //THE POLAR BEAR winny the poo is eating 5 units of food... winny the poo is eating units of food... winny the poo is running... winny the poo is killing prey... winny the poo is sleeping... winny the poo is swimming... THAT FINE but how come i can echo out each of the properties? why do these ways not work? Code: [Select] Bear::eat($units); Bear::eat(); Bear::run(); Bear::kill(); Bear::sleep(); or Code: [Select] $bear = new Bear(); $bear->$name; $bear->$weight; $bear->$age; $bear->$sex; $bear->$colour; or Code: [Select] echo Bear::eat($units); echo Bear::eat(); echo Bear::run(); echo Bear::kill(); echo Bear::sleep(); or Code: [Select] $bear = new Bear(); echo $bear->$name; echo $bear->$weight; echo $bear->$age; echo $bear->$sex; echo $bear->$colour; and the same goes for PolarBear if i try and get back any of the properties on a page i get nothing ??? i even tried putting it in a loop and that didnt work Code: [Select] $bear = new Bear(); foreach ($bear as $bears){ echo $bears->$name; echo $bears->$weight; echo $bears->$age; echo $bears->$sex; echo $bears->$colour; } whats wrong. why cant i get any results from these ? thanks So, I'm starting a new project and thought I would try a new approach at loading files and classes to process output. I think my logic is correct, but for some reason I'm getting a blank page. Basically instead of having seperate pages to output different functions and such, I store everything in one page. It's the same deal as the switch case approach, but it uses a foreach loop to cycle through the actions, classes, and functions which are stored in an array. Here's my index.php file: Code: [Select] <?php require('config.php'); include('languages/english.php'); include('classes/Template.php'); $template = new Template; $viewPages = array( 'category' => array('classfile' => 'Category.php', 'classname' => 'category', 'functions' => array('create', 'delete', 'modify', 'merge')), 'questions' => array('classfile' => 'Question.php', 'classname' => 'Question', 'functions' => array('create', 'delete', 'modify', 'votegood', 'votebad')) ); $currentPage = $_REQUEST['action']; foreach($viewPages as $action => $settings){ if($currentPage == $action){ require(INCLUDE_ROOT.'/classes/'.$settings['classfile']); $class = new $settings['classname']; $function = $_REQUEST['do']; $class->$function(); $template->loadTemplate($settings['classname']->viewFile, $vars = array()); if($template->message == FALSE){ die($template->message); } } } ?> Here's the Template class file: Code: [Select] <?php class Template { var $file; var $vars; var $message; function loadTemplate($file, $vars){ if(empty($file) || empty($vars)){ $this->message = LANG_ERR_7; } else if($file = file_get_contents(INCLUDE_ROOT.'/'.$file)){ $this->message = LANG_ERR_7; } else { foreach($vars as $key => $val) $file = str_replace('{'.$key.'}', $val, $file); } $this->message = FALSE; return $file; } } ?> I tried visiting the category action(index.php?action=category;do=create). This is the classfile for that Code: [Select] <?php class category { var $id; var $title; var $description; var $uri; var $message = array(); var $vars = array(); var $viewFile = ''; function create(){ if($_POST['submit']){ //Review the user input and make ure everything is ok $messages = array(); if($this->title == FALSE){ $messages['title'] = LANG_ERR_1; } else if(strlen($this->title) > 30 || strlen($this->title < 5)){ $messages['title'] = LANG_ERR_2; } else if($this->description == FALSE){ $messages['description'] = LANG_ERR_3; } else if(strlen($this->description) > 400 || strlen($this->description) < 10){ $messages['description'] = LANG_ERR_4; } else { $messages = FALSE; } if($messages != FALSE){ $this->messages = $messages; $this->viewFile = INCLUDE_ROOT.'/template/index_body.tpl'; } else { $this->title = htmlentities($this->title); $this->title = stripslashes($this->title); $this->title = htmlspecialchars($this->title); $this->description = htmlentities($this->description); $this->description = htmlspecialchars($this->description); $this->description = nl2br($this->description); $query = " INSERT INTO categories (c_title, c_desc) VALUES('".$this->title."', '".$this->desscription."')"; if(mysql_query($query)){ $this->message['succes'] = LANG_ERR_5; } else { $this->message['fail'] = LANG_ERR_6; } $this->viewFile = INCLUDE_ROOT.'/template/message_body.tpl'; } } else { $this->viewFile = INCLUDE_ROOT.'/template/create_category.tpl'; } } } ?> Now if you look at the Category class, the template file it sets is the "category_create.tpl" file, which I haven't created yet. I'm expecting there to be an error associated with the template class and the file_get_contents function that calls the file, but like I said, I'm just getting a blank page. I've never tried this approach before, so I have no idea what's causing this. Any help would be greatly appreciated. In javascript you can do multiple methods on the same line like: if(document.getElementById('myElement').className.match(/^[0-9]/)){/*Do something*/} in that we have getElementById() and match() on the same line, and it works the same as if you were to split them on multiple lines. Is it possible to do that with php? For example: $obj = new MyObject(); $obj->add(2, 3)->to_string(); Hi, I am trying to get my head around classes, interfaces and methods for different animals
this is what I have so far: <?php interface animal { function walk(); function fly(); function swim(); } class monkey implements animal{ const interface1 = "I am from test class"; function noise() { echo "ooh ooh ah ah!"; } function walk() { echo "monkey is walking"; } function fly() { echo "monkey is Flying"; } function swim() { echo "monkey is Swimming"; } public function display() { echo monkey::interface1; echo PHP_EOL; } } class bear implements animal{ const interface1 = "I am from test class"; function noise() { echo "Grrr!"; } function walk() { echo "Bear is walking"; } function fly() { echo "Bear is Flying"; } function swim() { echo "Bear is Swimming"; } public function display() { echo bear::interface1; echo PHP_EOL; } } $Obj = new monkey(); $Obj->display(); $Obj1 = new bear(); $Obj1->display(); ?> I'm a bit stumped as animal interface not calling all functions?! please help I can't find an explicit answer on this anywhere, but when you create a child class from an abstract class must you use ALL of the methods that are inside the abstract class in the new child class? Or are these methods just available to the child class to pick and choose?
Hi there, I am working on a PHP ecommerce website. I am going to install SSL on few of the pages. I need to install it on Apache web server coz thats the server our PHP website is running on. How we do go about installing SSL on PHP website. Can anybody please guide me in the right direction. All comments and feedback are always welcomed. Thank you! |