Tag Archives: php

Check if file exists in Symfony2

Check if file exists in Symfony2 If you want want to check if file exists in Symfony2 and which is not a twig template, you have to create a Twig Extension service and add a file_exists() function or whatever you want to call it in twig. This tutorial is more specific to the issue we have at hand,

PHP Simple HTML DOM Parser

domTree

PHP Simple HTML DOM Parser In this tutorial I will show you a great way to parse a webpage with plain PHP, in the same way you do with jquery. The syntax is very native and natural, and you will feel like home using it but first let’s thank the author of this library S.C. Chen

Transform a csv file to associative array in PHP

csv

 Transform a csv file to associative array in PHP There are a lot of  examples on how to take a CSV file and put it in an array, but the main problem about them is that the header and the rest of the content from the csv are placed on separate keys, both on the

Working with Entities in Symfony2

Working with Entities in Symfony2 Symfony is a very powerfull PHP framework that helps you do amazing projects in small amount of time. It has built in support for Doctrine which is an incredible tool for interacting with databases, not through tables but through php objects. First let’s see what is an ORM and after that

How to do a batch insert in MySQL?

mysql feature

How to do a batch insert in MySQL? In this tutorial, I will present you how to do a batch insert in mysql. Let’s say you want to insert some informations from an array into the database. In order for this to work efficient, you should have more than one information in that array. Why

How to sort a multidimensional array based on key?

snippets

How to sort a multidimensional array based on key? First of all, let’s give credit to the person who wrote this function. The problem ? Let’s say you have a multidimensional array and you want to sort based on a key that is not on the first level of the array, how would you do

How to detect a page refresh with PHP?

snippets

How to detect a page refresh with PHP? Sometimes you want to detect if the page was refreshed using “F5” key, or right click and “Reload” or any other method available. Either way, this can be detected somehow from server side. In this snippet, I will show you how to do this with PHP. Method

Symfony mapped entities error while generating getters and setters

snippets

Symfony mapped entities error while generating getters and setters If you ever used Symfony php framework, and you wanted to generate through command line the setters and getters for your entity after you defined everything in your entities files, and you got an error like this:

you probably want to know the solution of

The controller for URI is not callable in symfony

snippets

The controller for URI is not callable in symfony This is a very common error for symfony starters, and it happened to me also when I first tried the framework, so you have to follow two steps in order to debug this: First check First step is to make sure that your controller is actually

How to invoke dynamically a class method in PHP?

snippets

How to invoke dynamically a class method in PHP? Today will talk about calling a method from inside class, however you are in the situation of calling a method dynamically in a loop, for each element of an array. To do this we will make use of a php function called call_user_func.Using this function, you

Request an article ←