Jump to content

nik_jain

Members
  • Posts

    60
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by nik_jain

  1. Thank you! actually I struggle in the same manner with frameworks as well . Recently I tried learning zend and yii 2 Site Features: 1. Basic Search 2. Post page 3. 'browse/filter' page . Basically narrow down posts using category / date etc. Regular stuff.. Wordpress way: create post, post_type using csv row, import and use existing search, comments functionality. Core PHP way: Create database structure -> import csv implement every goddamn feature myself. be it comments to post, post_page , search functionality etc. The issue with frameworks/CMS: the trouble starts when implementing something not in the book/docs means googling too much... Say in wordpress I had to implement a form that anybody could post to, this proved tiresome. Not difficult, but trying to figure out how to implement required googling..
  2. One option might be to add a boolean column - 'is_guest' ? Set default value to false and work from there..
  3. Basically everytime I try to code a site in an existing CMS I find out that I spend 99% time trying to google out how the CMS works, how a particular thing is done and less time coding. I end up not using any CMS at all and just code my site in Core php. Now I have an idea for a site that whose development I think will really be speeded up if I use an exisiting CMS, instead of trying to implement every goddamn feature myself. I feel I am doing something wrong in the way I try to learn a CMS. or maybe I am just not using the right CMS. I have tried reading books / video tutorials / online tutorials etc Can anyone relate? Any tips / suggestions to offer ? I am most familiar with wordpress btw Thanks
  4. POST variables are returned as String afaik, so they needs to be converted into integer for integer comparison So this should do the job: if ((int)$value >= 0.0 && (int)$value <= 10.0) {
  5. I don't understand you, but a couple of pointers... 1. curl can return the error, if any for the current request. check it if it helps: http://php.net/manual/en/function.curl-error.php . Similarly there is curl_info 2. The values being passed to POSTFIELDS should be urlencode'ed 3. Referer doesn't seem right
  6. $someArray = json_decode($_POST['containerPositions'], true); The true parameter causes an associative array to be returned. If you need an ofject set it false http://php.net/manual/en/function.json-decode.php
  7. If you are not handy with Javascript it will require some learning... Basically you set code to send requests with javascript(ajax) every 1 second or so The requests (simple GET queries ) are sent to the server, site.com/ajaxHandler.php?check=1 Where the script ajaxhandler will check for whatever thing you need to check and echo out a response, which the javascript code will see and perform an action based on that. For syntax , just google.. 'ajax beginner' or something like that
  8. Yup Basically we are replacing index.html with index.php (index.php should be called automatically). HTML files cannot normally call php files. So rename index.html to index.php and add the code there. Its like this: Apache recieves request for site.com > it looks for specified files (generally index.html / index.php etc) If index.html it sends as is. index.php it processes it through PHP , which creates html text and sends it to apache , which sends it to the browser. HOWEVER you will also have to rename all instances of index.html in your other files to index.php, otherwise dead links... btw if you are interested to go deeper into PHP I strongly recommend a book/video tutorial series to grasp the basics.
  9. The aim is to be able to release 'something' a small library / Class etc to show off my programming skills and to practise some of those design patterns . But I am struggling to come up with ideas for anything. The few ideas that came to mind: 1. Some kind of responsive HTML generator that uses GRIDS from purecss.io - This maybe far too frontend'ish. I more of a backend guy 2. Timer Class to time things. Too easy I think.. 3. Any other suggestions please . I code in PHP and JavaScript Thanks
  10. The perfect way of parsing HTML in PHP is via the library 'Querypath' its a wrapper around DOM , so no regex. Also the syntax is very jQuery like..
  11. Nope , its a PHP class that requires to be processed server side using PHP. plain html files are generally passed as is from your server (website) to the client(user with the browser) without passing them through PHP. So to use it: you need to use a PHP file (say inde.php), that has the above code The following line : Tells PHP where to look for Mobile_Detect.php . In this case its the same directory as the inde.php file we created earlier. btw you can rename the inde.html file to inde.php , but that might break things depending on how the rest of your site is... Lastly I think the apache server can be configured to process html files as PHP, but I am pretty sure thats (a) not a good idea (b) not possible on shared hosting...
  12. http://stackoverflow.com/questions/9508029/dropdown-select-with-images
  13. Wouldn't AJAX / javascript be the way to handle it ? Send periodic aja requests to your server, to check if the perl script has done its thing. if it has return a response via AJAX and show the results.
  14. I don't think I understand what you require, but the string {age:30-50} is a json encoded string . You can get the value by $string = '{age:30-50}' ; $age_obj= json_decode($string) ; $age = $age_obj->age ; Something like that
  15. I see.. So I guess another way of saying what I want to ask is 'how to detect the BASE_URL automatically ?' If memory serves right then some frameworks do try to detect the base URL automatically while also giving an option to set it manually. ok googling around I found this: http://blog.lavoie.sl/2013/02/php-document-root-path-and-url-detection.html But I think the following way should also work, with any router. I don't see any gotchas in this, but there might be. $base = dirname($_SERVER['PHP_SELF']) ; if ($base === '/' || $base === '\\'){ $base = '' ; } $klein = new \Klein\Klein(); $klein->respond('GET', $base.'/hello', function () { return 'Hello World!'; }); $klein->dispatch();
  16. ->with() works nicely! Thanks $base = dirname($_SERVER['PHP_SELF']) ; if ($base === '/' || $base === '\\'){ $base = '' ; } $klein = new \Klein\Klein(); $klein->with($base, function() use($klein) { $klein->respond('GET', '/hello', function () { return 'Hello World!'; }); }); $klein->dispatch(); by hardcoding into .htaccess ? I kind of wanted a 'redistributable' solution..
  17. I was trying to use one of the many PHP routers like klein, when I kept hitting an issue. The issue was my root folder was a subdirectory of the www folder . So instead of requesting http://localhost/index.php (as one would if the index.php was located in /var/www) I was requesting http://localhost/issues/web/index.php (index.php in /var/www/issues/web) Naturally the router looked for a match for the whole path(issues/web/index.php) instead of just the relative path(/index.php) Which caused it not to match anything ! Questions: 1. Is this a viable solution for this problem (Got this from https://github.com/chriso/klein.php/wiki/Sub-Directory-Installation? Any possible gotchas I should be on the look out for ? $base = dirname($_SERVER['PHP_SELF']); // Update request when we have a subdirectory if(ltrim($base, '/')){ $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], strlen($base)); } //initialize router code. 2. This must be an extremely common situation! How do people deal with this ? OR is it simply not common for routers to be installed to subfolders and called from there ? Thanks
  18. Its like an elusive goal of mine. To be able to write big pieces of code that are reusable in multiple projects. For example: Lets say we are coding a simple 'Membership system'- login / signup etc. How would for instance something like routing would be handled in this so that it remains modular. Reusable in multiple projects that may be using a different router for their projects. Any guidance please ? Is there a book that shows how its done ?
  19. You could try replacing \n by \r\n as the line separator. As thats what the csv contains.
  20. Dude xpath and DOM are a pain! Try the library Querypath (its a wrapper around DOMDocument). It takes the pain out of these things.
  21. The PHP way would be to use cURL and send a POST request . But for something simpler , something that can record and replay your actions, you can try the imacros extension for firefox.
  22. I have spent the last few days going over Zend framework 2, and I am finding it extremely complex. Not saying it shouldn't be, but it seems to solve problems I never have come across (so to speak) . For instance: Routing is super complex. I usually use torophp - which is simple & gets the job done. Dependency injection - example of problem I have never come across. My motivations for learning zend, are - 1. To write modular reuseable code. 2. Learn advanced / modern PHP , as far as frameworks are concerned I just know codeigniter. 3. A framework with good long term support. Is there some other framework that is easier to learn ? and that would satisfy my requirements ? I have been programming in PHP for the last 2-3 years btw, so I know my way around Thanks
  23. I think it should be - var_dump(json_decode($response->GetProspectAsJSONResult, true));
  24. I figured it out! The problem was in this query. Mysqli doesn't like large offsets in large tables. So the solution was to simply add a WHERE product_id > ($offset value) and remove the OFFSET Now the part that at minimum took .06, takes only .005 Ah thanks for this, I haven't extensively used prepared statements. This was just an attempt to find the culprit.
  25. In the above loop the time taken by the call to get_rows_from_ppt($start, $atOnce); gradually (but slowly) increases over each iteration. When the loop starts it takes about .06 sec to execute, but after several thosand iterations the time taken by the same function is .2 seconds. If I let the script continue running, then it increases to .6 seconds. Why ? Here are the other 2 functions being called above: Edit: I forgot to mention the table is of the form : +------------+---------------------+-------+ | product_id | insertion_timestamp | price | +------------+---------------------+-------+ | 1123 | 1406719422 | 7323 | | 1123 | 1407313884 | 7323 | | 1123 | 1408284527 | 7323 | | 1123 | 1408381296 | 7323 | | 1124 | 1406719422 | 1831 | | 1124 | 1407313884 | 1831 | | 1124 | 1408284527 | 1831 | | 1124 | 1408381296 | 1831 | having a index on product_id
×
×
  • 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.