Skip to main content

Posts

Showing posts with the label Programming

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

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