php

How to append to a Laravel4 Blade yeild 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).

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

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

Technology: 

Simple MVC system in Drupal 6

I've recently started working on a custom module in Drupal 6 and i really disliked the idea to use built in functions for tables and/or to use embedded html into my module.

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: 

New home for PSR-0 and other proposals from PHP FIG (Framework Interop Group)

Since the old Google group link doesn't work anymore, here's the new home for PSR-0

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: 

Ajax / Jquery / PHP Open Source Web File Manager

It took a while, but I managed to find this pretty nifty web based file manager that has user management (with different backends) and if using the right plugins it even has ftp support.

Also it's well maintained, updated often, and best of all looks pretty damn nice.

How to check if the user is logged in Drupal 6 using php

I needed this snippet of code in a block to show different links based on the user's logged in state.

  1. <?php
  2. global $user;
  3. if ($user->uid) {
  4.     print "logged in";
  5. }
  6. else if (!$user->uid) {
  7.     print "please log in";
  8. }
  9. ?>
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.

Pages

Subscribe to php