This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class News extends CI_Controller { | |
public function index() | |
{ | |
$this->load->model('news_model', 'article'); | |
$data['news] = $this->article->get_all(); | |
$this->load->view('news_list', $data); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#subscribe_newsletter').click(function(){ | |
event.preventDefault(); | |
var form_data = { | |
name: $('#name').val(), | |
email: $('#email').val() | |
}; | |
$.ajax({ | |
url: $('#newsletter_url').val(), | |
type: 'POST', | |
data: form_data, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SubObject | |
{ | |
static $instances = 0; | |
public $instance; | |
public function __construct() { | |
$this->instance = ++self::$instances; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
{ | |
public $var1; | |
public $var2; | |
public static function __set_state($an_array) // As of PHP 5.1.0 | |
{ | |
$obj = new A; | |
$obj->var1 = $an_array['var1']; | |
$obj->var2 = $an_array['var2']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CallableClass | |
{ | |
public function __invoke($x) | |
{ | |
var_dump($x); | |
} | |
} | |
$obj = new CallableClass; | |
$obj(5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TestClass | |
{ | |
public $foo; | |
public function __construct($foo) | |
{ | |
$this->foo = $foo; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Connection | |
{ | |
protected $link; | |
private $server, $username, $password, $db; | |
public function __construct($server, $username, $password, $db) | |
{ | |
$this->server = $server; | |
$this->username = $username; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PropertyTest | |
{ | |
/** Location for overloaded data. */ | |
private $data = array(); | |
/** Overloading not used on declared properties. */ | |
public $declared = 1; | |
/** Overloading only used on this when accessed outside the class. */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyDestructableClass { | |
function __construct() { | |
print "In constructor\n"; | |
$this->name = "MyDestructableClass"; | |
} | |
function __destruct() { | |
print "Destroying " . $this->name . "\n"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MethodTest | |
{ | |
public function __call($name, $arguments) | |
{ | |
// Note: value of $name is case sensitive. | |
echo "Calling object method '$name' " | |
. implode(', ', $arguments). "\n"; | |
} |