Jump to content

sharal

Members
  • Posts

    31
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sharal's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Here's a good place to start, and yes - implementing the pattern yourself does give you a better understanding of how it works. You could for instance start here: http://net.tutsplus.com/tutorials/php/create-your-first-tiny-mvc-boilerplate-with-php/
  2. Well it doesn't change the behaviour of the parent class, it just extends it. I don't see where you apply the LSP then. Anyway, you should not ponder things as LSP even though it is vital for making code act as we expect it to, not just yet atleast. Or that depends on how much you can comprehend. The baseclass duck does not implement fly, because the general duck, the abstraction of duck is not able to fly.
  3. Lets say your page url was : "http://www.mysite.com/script.php?id=1" where 1 is the id of the contact information in the database you want to retrieve. first off you want to retrieve the "id" parameter which we have set to '1' in the url (script.php?id=1) we do that by using $_GET['id']; $_GET['urlParameterNameHere'] retrieves an url parameter from the url address, in this case id. $id = $_GET['id']; // will be equal to '1' if the url ends in ?id=1 it would be '2' if it ended in ?id=2 etc. $query="SELECT * FROM contacts WHERE id='$id'"; $result=mysql_query($query);
  4. You can try something like this, there might be some minor parse errors, it's just a rough sketch. Site with the image on: top page php script session_start(); if(isset($_POST['submitted'])) { $redirectPage = 'http://yourside.com/pageAccessedByClickingImage.php'; $_SESSION['access'] = 1; echo '<meta http-equiv="refresh" content="0;url='.$redirectPage.'" />'; } the image link: <form id="myform" action="" method="post"> <img src="someImage" onclick="document.getElementById("myform").submit()" /> <input type="hidden" name="submitted" value="1" /> </form> The page only accessible by clicking the image, top page php code: session_start(); if(!isset($_SESSION['access']) || $_SESSION['access'] != 1) { exit('You cannot access this page directly'); } The page only accessible by clicking the image, bottom page php code: $_SESSION['access'] = NULL; unset($_SESSION['access'];
  5. sharal

    fatih

    this should do the trick: <script type="text/javascript"> var added = 0; function bul () { if(added == 0) { var element = document.createElement("input"); element.type ="text"; element.name ="sehir"; element.id ="sehir"; element.size = "51"; document.getElementsByName("talep_form")[0].appendChild(element); added = 1; } } </script>
  6. Strange, I pasted your code directly into my editor and ran it - with no problems whatsoever.
  7. sharal

    fatih

    Hi bdmfatih. onchange doesn't work with php as it is a client side html attribute, it does however work with javascript which might also solve your issue. <script type="text/javascript"> function bul () { var element = document.createElement("input"); element.type ="text"; element.name ="sehir"; element.id ="sehir"; element.size = "51"; document.getElementsByName("talep_form")[0].appendChild(element); } </script>
  8. it has something to do with your static method probably, I dont usually work with those so afraid I can't help you. My best guess is that it's not possible to access non static class variables(as those are different from each instance of the object) from within the static method, you can however, always access static variables from inside the static method. Class someclass { private static $test = 'hello'; public static function something () { echo self::$test; } } $test = new someClass; $test::something();
  9. Btw you might find this interesting: http://www.developer.com/lang/article.php/3628381/The-Object-Oriented-Thought-Process-Index-Page.htm it's a short article of a book named the "object oriented thought process", it explains interfaces, abstract classes and all the basics quite well. http://www.developer.com/design/article.php/3635836/Objects-and-Interfaces.htm
  10. Do you actually have a class wrapping around that? As the error indicates you are using the $this operator outside of the objects scope. Can you try to post the whole class with the class declaration too?
  11. Or simply: $myvalue = uniqid(); echo $myvalue; http://dk.php.net/manual/en/function.uniqid.php
  12. (int) typecasts the variable as an integer, hence all non-integer values will be gone. is_numeric($number) returns true, if $number is a numeric, but does nothing more. You could also use: $var = filter_var($myInteger, FILTER_VALIDATE_INT); // validates http://www.php.net/manual/en/filter.filters.validate.php also $var = filter_var($myInteger,FILTER_SANITIZE_NUMBER_INT); http://www.php.net/manual/en/filter.filters.sanitize.php
  13. This should probably be changed: if (!isset($_POST["$submit"])) Into: if (isset($_POST["submit"])) If you do the !isset($_POST['submit']), then your validation won't run if $_POST['submit'] exists, which it does the moment you submit your form as your submit input is named "submit"
  14. You should consider namespaces in vast projects containing a lot of code, and possibly where you are multiple employees working on the project. It will save you a lot of potential problems if you use pseudo namespaces as pointed out by Thorpe. As for the constructor, it's best sticking to the magic method __construct(), for instance, when you rename your class, you won't have to rename your constructor.
  15. Yes it does work as a sort of contract too, abstract classes can leave methods that children must implement as well, then they have to be declared abstract (look below). And yes, an abstract class can provide both methods with implementations and methods that must be implemented by inheriting child classes. eg: <?php abstract class Duck { private $name; private $size; // lets assume that the implementation of how ducks eat food is different, from duck to duck public abstract function eat (); /* abstract methods within an abstract class does not contain a method body, just like those of an interface, and must be implemented by inheriting children */ } class MallardDuck extends Duck { private $gender; public function fly () { } public function eat () { /* as theres an abstract method in the Duck class that we are extending, we must implement it in child classes (just like interfaces) */ } } ?> A little tip on when to use abstract methods: When you know that something will be different in the inheriting classes, but yet it's a feature that is common. For instance: if the MallardDuck and the DecoyDuck both could eat food, but they ate it in different ways (the implementation would differ), then you should have an abstract method in the Duck class named eat(). Doing that, forces MallardDuck, DecoyDuck and all other ducks to implement their own way of eating. The abstract method works as a "contract" again, and it literally defines that all ducks must be able to eat, but they must implement their own way of doing that. Additionally, we can also define in the abstract parent class Duck, that all ducks can Quack, and implement it in the abstract parent class - because all ducks quack the same way, furthermore we can also define properties that are common for all ducks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.