Search and replace in the terminal

MacBook Pro affichant un éditeur de code

On Ubuntu it is possible to search and replace a word or phrase with a simple command line sed -i’s/original/new/g’ file.txt Explanation: sed = Stream EDitor -i = in-place (save in the original file) the strings in the command: s = the replacement command original = regular expression for the word to be replaced. new … Read more

Upload multiple files to an entity with Symfony4 and VichUploaderBundle

Code sur écran d'ordinateur

Preparation   To begin with, we need a Product entity as well as a ProductImage entity that will contain the names of the images. To do this, we use the command in our terminal VichUploaderBundle Setup As stated in the Symfony 4 documentation, we will use the VichUploaderBundle Then add the necessary “config/packages/vich_uploader.yaml” configuration file … Read more

Install WordPress and plugins with Composer

MacBook avec code sur un bureau

Installing WordPress via Composer has often been difficult, fortunately there is now a solution! WordPress On GitHub there is a project that is updated every 15 minutes with the latest version of WordPress. It is also the most used. https://github.com/johnpbloch/wordpress In the composer.json just indicate the project name. In this example, we can also indicate … Read more

PhpUnit – mock – internal set protected / private variable

MacBook avec code sur un bureau

Using mocks it is often necessary to give a value to a private or protected variable. To do this, just use the Reflection class. $basket – $this–getMockBuilder ('Basket') OriginalConstructor() -getMock(; $basketReflection – new ReflectionClass ($basket); $sessionId – $basketReflection–getProperty ('sessionId'); $sessionId-setAccessible (true); $sessionId-setValue ($basket, 'abc'); so the sessionId value in our Mock will be ‘abc’.

Yii: Create a personalized relationship between two tables

MacBook avec code sur un bureau

To make a custom relationship between two tables in a model, it is possible to add an additional option in the relation in which one indicates which foreign key should be used with which field. public function relations () { return array ( ‘NameRelation’ – array ( self::HAS_ONE, ‘otherTable, ”, ‘on”fk_otherTabletable.fk_otherTable ‘ otherTable.id’ ), ); … Read more