Без регистрации suggest link php

Laravel requires Composer to manage the project dependencies. So before installing Laravel, make sure you have Composer installed on your system. In case you are hearing about Composer for the first time, it"s a dependency management tool for php similar to node"s npm.

To install Composer on your machine, check this post:

Installing Laravel on Windows:

Follow the below steps to install laravel on windows machine. No matter you have xampp/wamp stack, it works for both. On WAMP, make sure to install laravel on "www" folder and on XAMPP, obviously the "htdocs".

STEP-1) Open "htdocs" folder on XAMPP, hold SHIFT key and right click on the folder, and choose "open command window here". Alternatively, you can open command window and change directory to "xampp/htdocs".

STEP-2) Enter the following command.

Composer create-project laravel/laravel my_laravel_site --prefer-dist

Here "my_laravel_site" is the folder name where laravel files will be installed. Change this to your liking.

STEP-3) Now it"s time to be patient as laravel installation is going to take some time.

STEP-4) Once installed, change directory to "my_laravel_site" (cd "my_laravel_site") on the command prompt and enter the below command.

Php artisan serve

STEP-5) This will show a message something like, "Laravel development server started:" along with an url.

STEP-6) Copy and paste the url on the browser. If things go right, you"d see the laravel welcome screen.

STEP-7) Done! You have successfully installed laravel on windows machine and ready to go with.

Setting Application Key:

Laravel requires little configuration after installation. It requires you to set the application key. This is a random string of 32 characters long used for encrypting session and other sensitive data. Usually this will be set automatically when you install laravel via composer or laravel installer.

In case it"s not set, you have to do it manually. First make sure to rename the ".env.example" file to ".env" on your application root. Then open command prompt and change to the laravel project folder. Now run the below command to generate the key.

Php artisan key:generate

Copy this generated key to the APP_KEY variable on ".env" file. Save and you are done.

Installing Specific Laravel Version:

The above given method will make composer to download and install the latest version of laravel. If you want to install earlier versions of laravel on your machine, make sure to include the respective version number on create-project command.

Composer create-project laravel/laravel=5.4 your-project-name --prefer-dist Read Also:

Likewise you can easily install laravel using composer on windows . I hope you find this tutorial useful. Please share it on your social circle if you like it.

Listening to what your visitors have to say, is always beneficial when planning new features or changes in your website. For a long time we"ve been limited to just setting up a contact form and hoping that quality feedback will follow, which unfortunately is not always the case.

Today we are taking things up a notch - we are applying the same social principles that have brought success to sharing sites such as Digg and delicious, and encourage visitors to suggest and vote on features that they want implemented on your website.

The XHTML

Starting with the new HTML5 doctype, we define the opening and closing head and title tags, and include the main stylesheet of the app - styles.css , in the document.

suggestions.php Feature Suggest w/ PHP, jQuery & MySQL | Tutorialzine Demo data = $arr; } } public function __get($property){ // This is a magic method that is called if we // access a property that does not exist. if(array_key_exists($property,$this->data)){ return $this->data[$property]; } return NULL; } public function __toString() { // This is a magic method which is called when // converting the object to string: return "
  • id.""> have_voted ? "inactive" : "active").""> ".$this->suggestion." ".(int)$this->rating."
  • "; } }

    The __toString() method is used to create a string representation of the object. With its help we can build the HTML markup, complete with the suggestion title and number of votes.

    The __get() method is used to route the access to undefined properties of the class to the $data array. This means that if we access $obj->suggestion , and this property is undefined, it is going to be fetched from the $data array, and returned to us as if it existed. This way we can just pass an array to the constructor, instead of setting up all the properties. We are using this when creating an object in ajax.php .

    Now lets proceed with the generation of the unordered list on the front page.

    suggestions.php require "connect.php"; require "suggestion.class.php"; // Converting the IP to a number. This is a more effective way // to store it in the database: $ip = sprintf("%u",ip2long($_SERVER["REMOTE_ADDR"])); // The following query uses a left join to select // all the suggestions and in the same time determine // whether the user has voted on them. $result = $mysqli->query(" SELECT s.*, if (v.ip IS NULL,0,1) AS have_voted FROM suggestions AS s LEFT JOIN suggestions_votes AS v ON(s.id = v.suggestion_id AND v.day = CURRENT_DATE AND v.ip = $ip) ORDER BY s.rating DESC, s.id DESC "); $str = ""; if(!$mysqli->error) { // Generating the UL $str = "
      "; // Using MySQLi"s fetch_object method to create a new // object and populate it with the columns of the result query: while($suggestion = $result->fetch_object("Suggestion")){ $str.= $suggestion; // Uses the __toString() magic method. } $str .="
    "; }

    After running the query, we use the fetch_object() method of the $result object. This method creates an object of the given class for every row in the result, and assigns the columns of that row to the object as public properties.

    PHP also manages the AJAX requests sent by jQuery. This is done in ajax.php . To distinguish one AJAX action from another, the script takes a $_GET["action"] parameter, which can have one of two values - "vote " or "submit ".

    ajax.php require "connect.php"; require "suggestion.class.php"; // If the request did not come from AJAX, exit: if($_SERVER["HTTP_X_REQUESTED_WITH"] !="XMLHttpRequest"){ exit; } // Converting the IP to a number. This is a more effective way // to store it in the database: $ip = sprintf("%u",ip2long($_SERVER["REMOTE_ADDR"])); if($_GET["action"] == "vote"){ $v = (int)$_GET["vote"]; $id = (int)$_GET["id"]; if($v != -1 && $v != 1){ exit; } // Checking to see whether such a suggest item id exists: if(!$mysqli->query("SELECT 1 FROM suggestions WHERE id = $id")->num_rows){ exit; } // The id, ip and day fields are set as a primary key. // The query will fail if we try to insert a duplicate key, // which means that a visitor can vote only once per day. $mysqli->query(" INSERT INTO suggestions_votes (suggestion_id,ip,day,vote) VALUES ($id, $ip, CURRENT_DATE, $v) "); if($mysqli->affected_rows == 1) { $mysqli->query(" UPDATE suggestions SET ".($v == 1 ? "votes_up = votes_up + 1" : "votes_down = votes_down + 1").", rating = rating + $v WHERE id = $id "); } } else if($_GET["action"] == "submit"){ // Stripping the content $_GET["content"] = htmlspecialchars(strip_tags($_GET["content"])); if(mb_strlen($_GET["content"],"utf-8")query("INSERT INTO suggestions SET suggestion = "".$mysqli->real_escape_string($_GET["content"])."""); // Outputting the HTML of the newly created suggestion in a JSON format. // We are using (string) to trigger the magic __toString() method. echo json_encode(array("html" => (string)(new Suggestion(array("id" => $mysqli->insert_id, "suggestion" => $_GET["content"]))))); }

    When jQuery fires the "vote " request, it does not expect any return values, so the script does not output any. In the "submit " action, however, jQuery expects a JSON object to be returned, containing the HTML markup of the suggestion that was just inserted. This is where we create a new Suggestion object for the sole purpose of using its __toString() magic method and converting it with the inbuilt json_encode() function.


    The jQuery

    All of the jQuery code resides in script.js . It listens for click events on the green and red arrows. But as suggestions can be inserted at any point, we are using the live() jQuery method, so we can listen for the event even on elements that are not yet created.

    script.js $(document).ready(function(){ var ul = $("ul.suggestions"); // Listening of a click on a UP or DOWN arrow: $("div.vote span").live("click",function(){ var elem = $(this), parent = elem.parent(), li = elem.closest("li"), ratingDiv = li.find(".rating"), id = li.attr("id").replace("s",""), v = 1; // If the user"s already voted: if(parent.hasClass("inactive")){ return false; } parent.removeClass("active").addClass("inactive"); if(elem.hasClass("down")){ v = -1; } // Incrementing the counter on the right: ratingDiv.text(v + +ratingDiv.text()); // Turning all the LI elements into an array // and sorting it on the number of votes: var arr = $.makeArray(ul.find("li")).sort(function(l,r){ return +$(".rating",r).text() - +$(".rating",l).text(); }); // Adding the sorted LIs to the UL ul.html(arr); // Sending an AJAX request $.get("ajax.php",{action:"vote",vote:v,"id":id}); }); $("#suggest").submit(function(){ var form = $(this), textField = $("#suggestionText"); // Preventing double submits: if(form.hasClass("working") || textField.val().length