Jump to content

hansford

Members
  • Posts

    562
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by hansford

  1. hansford

    MVC

    For one thing...modern frameworks are constantly being updated and improved. Another thing is that is what companies want when looking to hire a developer. You should understand the MVC design pattern and how each part works, but then go learn a modern framework.
  2. This question is rather specific pertaining to a Wordpress plugin of which there are numerous. You might be better off trying to post your question to the plugin QA site. https://wordpress.org/support/plugin/advanced-custom-fields
  3. hansford

    MVC

    I wrote a custom one when I was trying to wrap my head around it. This is what my index.php page looks like. <?php require($_SERVER['DOCUMENT_ROOT'] . '/config.php'); require_once(ROOT . '/common.php'); // set the path separator define('PS','/'); require_once(APP . '/common.php'); // load system files require_once(SYS . 'Model.php'); require_once(SYS . 'Load.php'); require_once(SYS . 'View.php'); require_once(SYS . 'Controller.php'); require_once(SYS . 'Router.php'); // load the database require(DB); // load routes configuration require(APP . '/config' . PS . 'routes.php'); // launch application $router = new Router($routes); $router->init();
  4. Hi guys and girls, A recruiter asked me to do this coding challenge and was wondering if you had a more elegant solution or your thoughts on it. EXERCISE FOR DEVELOPER CANDIDATES: Unit Number Sorting Exercise We often deal with unit number / resident name data. These two pieces of information are used by our users to identify a lease. Many of our screens and reports show a list of leases. The task is to sort lease data read from a file and to print the sorted data to STDOUT. The data looks as follows (sample also attached): #50 - Smith #8 - Johnson #100 - Sanders #1B - Adams #1A - Kessenich Each line contains a unit number and a resident name. The data should be sorted by unit number. Develop a solution in PHP and one other language of your choice that reads the data from a file and prints the data (sorted by unit number) to STDOUT. The printed strings should not be modified from how they appear in the input file. Here is my solution: <?php define('br','<br />'); // open the file $fp = fopen('input.txt','rb+'); if (false === $fp) { die ('failed to open file'); } $numbers = array(); $letters = array(); // read the file line by line while (($line = fgets($fp, 1024)) !== false) { // split the string by unit number and name $str = explode(' - ',$line); // separate unit numbers from units with letters if (preg_match('/[a-zA-Z]/', $str[0])) { $letters[$str[0]] = $str[1]; } else { $numbers[$str[0]] = $str[1]; } } if ( ! feof($fp)) { die ('error reading file'); } fclose($fp); // sort each array ksort($numbers,SORT_STRING); ksort($letters,SORT_STRING); // merge arrays with unit letters appearing first $output = array_merge($letters, $numbers); // output data foreach ($output as $key => $value) { echo $key . ' - ' . $value . br; }
  5. You are over-thinking this whole thing. You can call whatever class/function you want in the PHP file that will be accessed by your Ajax call. in the data you pass to your PHP page, you can tell it what class should be called, what function etc. In this following example we have 'action' which tells your PHP page to call the "delItem" method on a known class and pass the method the "item" argument. $.ajax({ url: 'http://www.yourwebsite.com/file_name.php', type: 'POST', data: {action: 'delItem',item: item}, success: function (response) { if (response.status === 'success') { console.log("success"); $("#myModal").modal('hide'); $('#respostas .modal-title').html('Sucesso'); $('#respostas .modal-body').html('Informação: ' + response.message); $('#respostas').modal('show'); $('#respostas').on('hidden.bs.modal', function () { window.location.reload(true); }); } } });
  6. JavaScript and PHP don't know the other even exists. In your Ajax call set the URL to call the PHP file which will create your object and call your class.
  7. PHP and JavaScript don't mix like that. You have PHP tags inside a JavaScript file. JavaScript has no idea what the hell that is and visa-versa. Explain what you are trying to do and we can help.
  8. Requinix, memory lane. Look here at this related post you made back in 2008. http://forums.devnetwork.net/viewtopic.php?f=1&t=113664
  9. If this mystery application can do that then why can it not change the file which holds links to the source. file_get_contents() can grab all the data from a file - yes. Then you can take that string, in memory, and put it wherever you want.
  10. The rules went out the window long ago when MVC stopped matching up to real world of computer use. "Business Rules" belong in the model. MVC is a pattern, not a rule. All of the frameworks around today break the rules. I know I'm not telling you anything you don't already know. I'm just arguing lol
  11. There is argument on both sides of this debate. Personally, I handle validation from within the controller. No need to clutter up your controller with validation statements though - create a validation class and let it handle all of that.
  12. Given your example: mypage.php <?php error_reporting(E_ALL); ini_set('display_errors',1); if (isset($_GET['number'])) { $number = $_GET['number']; } if (isset($_GET['word'])) { $word = $_GET['word']; }
  13. If everything is "ok" why not close the topic and mark it as "Answered".
  14. I'm not going to read a ton of code fragment and try to make sense of it. There are alternative ways of sending email using PHP, but the most reliable way is with PHPMailer. If you have issues getting it set up. Post another question. https://github.com/PHPMailer/PHPMailer
  15. You are going to have to use Ajax calls if you want to dynamically shift the questions up or down based on vote clicks. As far as initially displaying the page. <form action="feed.php" method="post"> <textarea required="" name="question" placeholder="Write Something..." id="text" cols="30" rows="10"></textarea> <input type="submit" name="submit" value="ask"> </form> feed.php if ( ! isset($_POST['question'])) { // give error or send them back to the page etc. exit; } // here is where your database will come in // based on the number of votes you display the page html
  16. Just use a capturing group for the digits as you already know the other part. {gallery:(\d+)}
  17. All of it is obsolete unless you are just practicing or testing code fragments. Other than the manual https://secure.php.net/manual/en/index.php Another good reference is: http://www.phptherightway.com/
  18. $sql = "SELECT status from users WHERE id={$_SESSION['username']}"; if ( ! $result = $mysqli->query($sql)) { //do something } If you want to log users out after so much time of inactivity then put a timestamp column in your table and each time they do an activity check the current time against the db time and log them out if it's been too long or update the timestamp column.
  19. Hopefully, this makes requinix' comments a little more clear. Shape.php abstract class Shape { public abstract function getArea(); public abstract function getPerimeter(); public abstract function scale($scale); } Rectangle.php class Rectangle extends Shape { private $width; private $height; public function __construct($width, $height) { $this->width = $width; $this->height = $height; } public function getArea() { return $this->width * $this->height; } public function getPerimeter() { return $this->width * 2 + $this->height * 2; } public function scale($scale) { $this->width *= $scale; $this->height *= $scale; } } index.php error_reporting(E_ALL); ini_set('display_errors',1); define('br','<br />'); $rect = new Rectangle(3,4); echo "Area of 3 x 4 rectangle is: {$rect->getArea()}" . br; echo "Perimeter of 3 x 4 rectangle is: {$rect->getPerimeter()}" . br; echo '-------------------' . br; echo "After scaling a 3 x 4 rectangle by a factor of 2" . br; echo '-------------------' . br; $rect->scale(2); echo "Area of scaled rectangle is: {$rect->getArea()}" . br; echo "Perimeter of scaled rectangle is: {$rect->getPerimeter()}" . br;
  20. I hated Dreamweaver 14 years ago, used it on one project which required we use it, and haven't used it since. Can't you just hand code what you need - they will never know.
  21. $now = time(); $past = strtotime($row['TimeStamp']); $elapsed_minutes = floor(($now - $past) / 60); if ($elapsed_minutes >= 20) { // do something }
  22. Just because it's possible doesn't mean it's best practice. function growl_notification( $context ) { if ($context['user']['mentions'] > 0) what not pass the value to function
  23. Most data that gets passed around through sessions and hidden form fields seems to be non-critical data. Google and Facebook don't seem to think the data they pass around about you is all that "critical". However, my bank and credit card companies sure do. They will log me out if I spend too long taking a leak in the bathroom.
  24. Leave it out, leave it an evil empty string it's still going to submit back to the submitting page as of now. The specs say a lot of things, but the browsers have the last say in whether it's implemented or not. However, in the nature of goodwill and standards promotion, if you're going to submit back to the page, just omit the tag(edit: attribute) and make everyone happy.
  25. Since you are using international chars, use utf-8 for your encoding. $.ajax({ url: "get_id.php", type: "POST", dataType: "json", contentType: "application/x-www-form-urlencoded;charset=utf-8", data : {action: 'visitaValidacaoByUserAdmin', id_visita: 'id_visita', plano: 'plano', valido: 'valido'}, cache: false, success: function(response) { alert(response['message']); } PHP page example: <?php error_reporting(E_ALL); ini_set('display_errors', 1); // set headers header("Content-Type: application/json; charset=utf-8"); if (isset($_POST['action'])) { // call function $ret = $_POST['action'](); // return result echo json_encode($ret); } function visitaValidacaoByUserAdmin() { return array("status" => "success", "message" => "A visita já foi validada...Obrigado"); }
×
×
  • 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.