I have some confusion between those two patterns: singleton Check if the instance exists return it, or create a new one. Registry Check if the instance exists return it, or create a new one and store it. What the difference between them? Answer Both are about instance control. The difference is that Singleton…
php call class function by string name
How can I call a normal (not static) class function by its name? The below gives an error saying param 1 needs to be a valid callback. I don’t want the function to be static, I want it to be a normal function, and all the examples I’ve seen so far had them static. Answer The callback syntax is a
Joomla – Controller task that returns JSON data
I have the task run in my controller. I want it to return JSON data. As it stands, I am getting my JSON data wrapped inside the template HTML. How do I tell Joomla to just return JSON data from the …
Redirect only WordPress homepage with a 301 redirect
I have a blog, lets say example.com and another blog installed in example.com/np which is not multisite but a different WordPress installation. What I want is to redirect example.com homepage only to example.com/np. It would be great if that redirection is a 301 moved permanently redirection. If I place the 3…
Sort by date function with variable field name
The problem I’m having is passing the variable field_name to the date_compare function, which can only take two variables due to the usort method. date_compare function must also be wrapped in a variable to avoid redeclaring a function if it is called more than once. m I even going about this the right …
How to echo to console in Laravel and Artisan?
I was curious, I’m using Laravel and Artisan for my migrations. Is there a method to output information to the console? I can’t seem to find any information on this. For example: Answer Don’t know if you are using Laravel 3 or Laravel 4, and if its also possible in Laravel 3, but i found thi…
Delete specific characters in text-file php
I have a text like that : I want to delete the , in front of frank or eclipse, it can be any word. My idea is to check if with have a comma before Eclipse:, or accueil: and if with have one then we delete only the comma to have : But how can we delete just one commat
manipulate a result set from laravel eloquent
I’ve just picked up laravel after deciding to move to a php framework. I’m retrieving a result set of articles from a database using an eloquent query: this works fine and results come out as expected. However I now want to change the format of the article date from the mysql date format to anothe…
PHP Multiple Username & Passwords
So, this is probably the simplest question I could ever possibly ask.. Though it is driving me insane. In my login system, I have it set up to read the username and password from a standalone file “users.php” inside it contains I can not, for the life of me figure out how to make it read multiple …
Laravel 4 always returns HTTP status code 200
I have below code in error.php, which is triggered using App::abort(404, $error) in my controller. Still my response status code is 200(ok). I tried with various error codes like 400, 403 Answer For anyone still googling this problem: I was struggling with this problem for hours. For me the problem was caused…