Monday, 26 May 2014

Error message Strict standards: Non-static method should not be called statically in php

Error message Strict standards: Non-static method should not be called statically in php


// Your method could be:
public function customFunction() {
  // your code here
}

// or could be:

function customFunction() {
  // your code here
}

// To fix this you can do this method:
// Put static or public static
public static function customFunction() {
 // your code here
}

Your method is missing a static keyword.

For more information about static keyword read here:
http://de2.php.net/manual/en/language.oop5.static.php

Remove first or last character in a string (PHP)

Remove first or last character in a string (PHP)

Here's a simple way to accomplish it:

Remove first character:
$string = ",a,b,c,d,e";
echo substr($string, 1);

Remove last character:
$string = "a,b,c,d,e,";
echo substr($string, 0, -1);

For more information about substr() function, you can read the documentation here:

How to load a model or library in Codeigniter

There are two ways to accomplish it.


First, the standard way:
$this->load->library('yourlibrary');
$this->load->model('yourmodel');

Second, you can use this if you want to load a model or library outside the controllers or models folder.
private $ci; // Create a private PHP variable

// Get codeigniter instance and assign it to $this->ci
public function __construct() { 
$this->ci = get_instance(); 
}

Now you can load Codeigniter library using this code:
$this->ci->load->library('yourlibrary');
$this->ci->youtube->callYourCusomFunction($example);

and load Codeigniter model using this code: 
$this->ci->load->model('yourmodel');