Jump to content

hansford

Members
  • Content Count

    562
  • Joined

  • Last visited

  • Days Won

    4

hansford last won the day on November 29 2016

hansford had the most liked content!

Community Reputation

16 Neutral

About hansford

  • Rank
    Prolific Member

Profile Information

  • Gender
    Male
  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. hansford

    Noob in need of help

    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. hansford

    code challenge

    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. hansford

    Ajax call php class function?

    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. hansford

    Ajax call php class function?

    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. hansford

    moving a file to another directory

    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. hansford

    moving files as blobs to mysql database

    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. hansford

    Controller or Model

    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. hansford

    Controller or Model

    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. hansford

    Sticky Topics

    If everything is "ok" why not close the topic and mark it as "Answered".
  14. hansford

    edit php form to send email

    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. hansford

    need to convert code dynamically

    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
×

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.