Multiple GitHub Accounts and Repositories

We work in an environment where we have multiple GitHub accounts that is tied to different repositories. It took us a while to figure out how to properly set this up, so that the correct identify is tied to the correct repository. Let me walk you through an example on how we did it. Assuming that you have 3 identity, ie. 3 private keys, tied to 3 different GitHub repository. ...

May 12, 2023

Yii2 Internationalization (i18n) for advanced template

We are working on a project that makes use of Yii2 advanced template. This project needs to support Internationalization (i18n). In each of our application, we have a translation configuration. This is needed to generate the translation. The files would be generated in backend/messages, common/messages or frontend/messages. Here’s a sample. <?php // backend/config/i18n.php // common/config/i18n.php // frontend/config/i18n.php return [ 'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..', 'languages' => [ 'zh-CN', ], 'translator' => 'Yii::t', 'sort' => true, 'removeUnused' => true, 'markUnused' => true, 'only' => ['*.php'], 'except' => [ '.svn', '.git', '.gitignore', '.gitkeep', '.hgignore', '.hgkeep', '/assets', '/command', '/config', '/mail', '/messages', '/modules', '/runtime', '/tests', '/vagrant', '/vendor', '/views/user/settings', '/web', '/widgets', ], 'format' => 'php', 'messagePath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'messages', 'overwrite' => true, ]; Here are some samples of how the text should be wrapped. ...

May 12, 2023

Yii 2 Codeception Fixtures Gotcha

We use MongoDB (important point) with our Yii 2 applicaton. While setting up our API test fixtures in our Cest file, $I->grabFixture was not able to find the data we wanted eventhough we have defined it within the dataFile. [yii\base\ErrorException] Trying to get property 'client_id' of non-object Here’s what the dataFile looks like. <?php // This doesn't work. return [ 'client_one' => [ 'client_id' => 'mytestclient', ], ]; After some experimentation, we’ve found that we need to set the _id within the dataFile in order to get $I->grabFixture to work properly. ...

July 17, 2021

Yii 2 Codeception API Test

My API uses the Yii2 advanced template. It uses symfony/dotenv to read the .env. The .env is loaded in all the configurations. $dotenv = new Symfony\Component\Dotenv\Dotenv; $dotenv->load(__DIR__ . '/../../.env'); While running the Codeception api test, I came across this error. [PHPUnit\Framework\Exception] Undefined index: HOST at ../common/config/main-local.php:7 After much digging around, I’ve realized that I need to load Symfony\Component\Dotenv\Dotenv in common/config/codeception-local.php Thus, I have updated that file in the environment folder, and reran php init. ...

June 30, 2021

Yii 2 Four oh Four Not Found

After setting up a new application using Yii 2 Advanced Project Template, the very first time you want to load your new controller, if you are met with a 404 Not Found, one very likely cause is that you do not have a .htaccess in your web folder.

June 29, 2021

Yii2 URL manager cache class

You might come across the below warning if you have not set a cache to your Yii2 application while using URL manager. Unable to use cache for URL manager: Failed to instantiate component or class "cache". In order to remove that warning, setup a cache in your application’s configuration. We are using the DummyCache class here as we have yet to decide on one that we want to use. 'components' => [ 'cache' => [ 'class' => 'yii\caching\DummyCache', // FIXME ], ],

April 9, 2020

Yii2 Log using FileTarget

Here’s a sample Yii2 FileTarget configuration (to be added to the application’s configuration) used for logging. This configuration overwrite the default log file location, doesn’t capture the global PHP variables and also, adds a prefix to the log entry. 'bootstrap' => [ 'log', ], 'components' => [ 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'info'], // Custom log file. Default log file will appear in @runtime/logs 'logFile' => dirname(__DIR__) . '/log/app.log', // 'logVars' => [], // Custom prefix. 'prefix' => function ($message) { $request = Yii::$app->getRequest(); $ip = $request instanceof yii\base\Request ? $request->getUserIP() : '-'; $controller = Yii::$app->controller->id; $action = Yii::$app->controller->action->id; return "[$ip][$controller][$action]"; } ], ], ], ],

April 9, 2020

S3cmd on CentOS 7

S3cmd is a command line tool that we’ve used for uploading, retrieving and managing data in Amazon S3. To install S3cmd, you just need to run the install command. yum install s3cmd

March 20, 2020

Setup User and RBAC Management in Yii2

My goal for this exercise is to have User and RBAC management in my Yii 2 application. I’ve started out with the Yii 2 Basic Project Template and I would be adding the Yii2-user and Yii2-rbac extensions to my web application. Here are some of the steps I have taken to install and configure the extensions. Step 1: Installation Install the packages. composer require dektrium/yii2-user composer require dektrium/yii2-rbac Step 2: Configure the web application NOTE: Make sure that you don’t have user component configuration in your config files. Add the user and rbac module to the web applcation config. ...

August 26, 2019

Send Telegram Message in Group using VB Script

Here’s a vb script snippet that I have used to send Telegram message in a group from an Excel sheet. Sub sendTelegramMessage() Set objHttp = CreateObject("MSXML2.ServerXMLHTTP") ' Change these accordingly strChat = "<chat_id>" strText = "*Test*\r\nThis is a message" strUrl = "https://api.telegram.org/bot<token>/sendMessage" ' Leave these alone strMode = "markdown" strJson = "{""chat_id"": """ & strChat & """, ""text"": """ & strText & """, ""parse_mode"": """ & strMode & """}" objHttp.Open "POST", strUrl, False objHttp.setRequestHeader "Content-type", "application/json" objHttp.send strJson End Sub

August 17, 2018