Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: oliver
- * Date: 21.04.18
- * Time: 16:50
- */
- require_once "../lib/tpl.php";
- $list = "list.html";
- $add = "add.html";
- $cmd = isset($_GET["cmd"]) ? $_GET["cmd"] : "list";
- $data_array = [];
- class Person
- {
- public $firstName;
- public $lastName;
- public $phone;
- public function __construct($firstName, $lastName, $phone)
- {
- $this->firstName = $firstName;
- $this->lastName = $lastName;
- $this->phone = $phone;
- }
- }
- function put_data()
- {
- $firstName = $_POST["firstName"];
- $lastName = $_POST["lastName"];
- $phone = $_POST["phone"];
- $file = 'data.txt';
- //"\n" . $firstName . ":" . $lastName . ":" . $phone
- file_put_contents($file, "asdasdasdasdasdasd", FILE_APPEND);
- $data_array = read_item();
- return render_template("main.html", ['$table' => "list.html", '$data_array' => $data_array]);
- }
- function read_item()
- {
- $data = file_get_contents("data.txt");
- $lis = explode("\n", $data);
- if ($lis == "") {
- } else {
- foreach ($lis as $value) {
- $personInfo = explode(":", $value);
- list($firstName, $lastName, $phone) = $personInfo;
- $data_array[] = new Person($firstName, $lastName, $phone);
- }
- return $data_array;
- }
- }
- if ($cmd == "list") {
- $data_array = read_item();
- print render_template("main.html", ['$table' => $list, '$data_array' => $data_array]);
- } elseif ($cmd == "add") {
- print render_template("add.html", ['$table' => $add]);
- } elseif ($cmd == "add_all") {
- file_put_contents($file, "asdasdasdasdasdasd", FILE_APPEND);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement