php

If you need more help on the topic feel free to add a comment or create a new post on the Forum

How to append to a Laravel4 Blade yield template section from the controller

If you were using Section::append() in your old Laravel 3 controllers and you're trying to figure out how to achieve the same thing in Laravel 4 fear not I've got the answer (with the help from the bigger Laravel community, thanks guys).

\View::inject('section_name', 'content');
\View::stopSection(false);

This is temporary a two line solution since extendSection isn't yet available for easy access.

Technology: 

Why using "or die()" in PHP is a bad practice

Daniel wrote a nice article on phpfreaks.com describing why it's bad practice to use "or die()" in your php code.

Reasons such as:

  1. It's not a very nice way to present the user with an error message.
  2. Using for instance the mysql_error() call with it, as many people do, exposes information that should never get output in a production environment
  3. You cannot catch the error in any way.
  4. You cannot log the error.
  5. You cannot control whether it should be output to the screen or not. It's okay to do that in a development environment, but certainly not in a production environment.
  6. It prevents you from doing any sort of cleanup. It just ends the script abruptly.

Technology: 

How to get output of a php function into a variable

It's pretty simple, and it can be very helpfull when for some reason you need to do a conditional display on an output from a function, but for legacy/compatibility reasons you can't modify that function.

  1. <?php
  2.     ob_start();
  3.     echo 'I like cookies';
  4.     $myStr = ob_get_contents();
  5.     ob_end_clean();
  6. ?>

Technology: 

How to reset PrestaShop Admin Password

If for some reason you've forgot your admin password and because of a faulty update the email you receive with the password reset is bad you can do the following sql command

  1. UPDATE employee SET passwd = md5("COOKIE_KEYpassword_here”) WHERE email = “email_for_who_you_want_to_change_the_password”;

You can find the COOKIE_KEY in config/settings.inc.php

Remember that the password must be greater than 8 characters in length and that it has to be put without spaces to the right of the COOKIE_KEY value.

Technology: 

Random Joomla 1.5 Logout

I was receiving some complaints from a customer that he was getting randomly logged out when using the administration section of his website.

He has a Joomla 1.5 install with the legacy plugin enabled and according to this Joomla Bug you have to have the Remember me Plugin to have an higher priority than the Cache and Legacy plugins.

For solving this, I've made Remember me to have priority 1, Legacy 2 and Cache 3.

Technology: 

SolarPHP How to use unlimited functions in a View Helper

I was chatting on irc with dmytrok (kudos to him about the tip below) about the Solar View Helpers and it seems there's a very simple way of using multiple functions in a solar view helper.

As you know, for creating a Solar View Helper you create a class like:

  1. class Vendor_View_Helper_MyTest extends Solar_View_Helper {
  2.  
  3.     public function myTest()
  4.     {
  5.         // logic here
  6.     }
  7. }

And then you can call it in your views by using $this->myTest() and all will go well.

Technology: 

Pages

Subscribe to php