Skip to main content

Posts

Showing posts with the label PHP

Some coding convention rules, working effectively with Legacy code

 https://softwareengineering.stackexchange.com/questions/133404/what-is-the-ideal-length-of-a-method-for-you Method length should be 15 (soft limit). We can do “testing to detect change.” In traditional terms, this is called regression testing. We periodically run tests that check for known good behavior to find out whether our software still works the way that it did in the past. Let’s do a little thought experiment. We are stepping into a large function that contains a large amount of complicated logic. We analyze, we think, we talk to people who know more about that piece of code than we do, and then we make a change. We want to make sure that the change hasn’t broken anything, but how can we do it? Luckily, we have a quality group that has a set of regression tests that it can run overnight. We call and ask them to schedule a run, and they say that, yes, they can run the tests overnight, but it is a good thing that we called early. Other groups usually try to schedule regressio...

PHP str_pad, Laravel PHP static function call

https://www.php.net/manual/en/function.str-pad.php Useful when for example add 0000 prefix to and ID (int) STR_PAD_LEFT / RIGHT https://www.w3resource.com/mysql/string-functions/mysql-lpad-function.php https://stackoverflow.com/questions/3446538/cleanest-way-to-skip-a-foreach-if-array-is-empty https://laravel.io/forum/07-28-2014-error-using-this-when-not-in-object-context $table is an instance variable, not a static variable, so you can't use it in a static function (basic PHP). Damn basic PHP that I miss, and many interview question asked this shit. Yeah, update Model func remove static and update Controller call: // Model public function findMyReviewedShop()  {} // Controller $data = (new AreaModel)->findMyReviewedShop($user_id, $area_id); // instead of :: https://stackoverflow.com/questions/34947862/how-to-use-hasmanythrough-with-more-than-3-tables-in-laravel Questions: 1. Is relation query return all related data ? ie. review->shopdata ... This is...

Một số kinh nghiệm phỏng vấn Web Developer - PHP

Diamond problem (ambiguous in inheritance) https://stackoverflow.com/questions/2064880/diamond-problem Class A, Class B some method here ... print A method, B method ... Question what output and why ? ... If we want class B method print A's method output ... => how to do that ? define final static self accept static method, properties. $this can not.... see more here :   https://www.wisdomjobs.com/e-university/object-oriented-programming-in-php-interview-questions.html SQL design Product, Orders, query best sell each month ... In PHP, Overloading is possible http://200-530.blogspot.in/2013/04/oop-magic-methods.html

Yii 2 Validation

Bài này note lại validation trên Yii cả 1.1 lẫn 2.xx Doc của Yii cũng tương đối nhưng không nhiều guide, tuts như Laravel hay các FW nổi hơn. Ngoài ra Doc của Yii của 2 version 1, 2 cứ loạn lên. Bản thân doc và API guide cũng dễ gây nhầm lẫn. http://www.yiiframework.com/doc-2.0/guide-tutorial-core-validators.html#integer Controller: public function actionCreate($project_list_id=null) { $request = Yii::$app->request; $inputs = $request->post(); if(!$project_list_id) { $project_list_id = $request->get('project_list_id'); } $is_new = !isset($project_list_id) ? true : false; $dropdownArray = $this->getDropdownArray(); $projectListModel = new ProjectListRecord(); $projectModel = new PmsRecord(); if(isset($project_list_id)) {   // check on edit or create $projectListModel = ProjectListRecord::findOne(['id' => $project_list_id, 'delete_flg' => 0]);        $projectModel = PmsRecord::findOne(['pr...

PHP Google API - Calendar

http://livingcode.co/index.php/tag/one-time-authorization-code/ http://martinfowler.com/articles/command-line-google.html New API doc here: https://developers.google.com/api-client-library/php/auth/web-app library: https://github.com/google/google-api-php-client index.php <?php // require_once 'google-api-php-client/autoload.php'; require_once 'google-api-php-client/src/Google/autoload.php'; session_start(); $client = new Google_Client(); $client->setAuthConfigFile('client_secrets.json'); $client->setAccessType("offline"); $client->addScope(Google_Service_Calendar::CALENDAR); if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {   $client->setAccessToken($_SESSION['access_token']);   // echo $client->getAccessToken();   $cal = new Google_Service_Calendar($client); $params = array( //CAN'T USE TIME MIN WITHOUT SINGLEEVENTS TURNED ON, //IT SAYS TO TREA...

Some Source code used often.

Mobile-Detect. Use simple code below: include 'Mobile_Detect.php'; $detect = new Mobile_Detect(); // Check for any mobile device. if ($detect->isMobile()) // mobile content else // other content for desktops Source code download here: Mobile Detect In Javascript, there are many script or lib to do this. Here one of mine: @extends('layouts.main') @section('head') @stop @section('content') login!! Facebook or Youtube login 【Sample CHECK!】 login!! screen 13 screen 15 screen 14 Some msg 3-12-12 笹川記念会館 Copyright ©C Official Web All rights reserved. @stop @section('script') @stop My script above is one of my index page. It write in Laravel bl...