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
<style> | |
iframe { border:none;border-bottom:1px solid #ccc;width:100%;height:250px; } | |
body, * { font-family:Consolas,"Lucida Console","Lucida Typewritter","Courier New",Courier,monospace; } | |
</style> | |
<?php | |
class FOO { | |
public $f; | |
} |
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
(function($){ | |
function time_to_hms (time) { | |
var amounts = { | |
hours: 60*60, | |
minutes: 60, | |
seconds: 1 | |
}, | |
hms = [], | |
unit = '', | |
amount = '', |
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 | |
// Example on how to handle JSON responses | |
if ($session->logged_in()) { | |
$json_response = array( | |
'error' => FALSE, | |
'user_id' => $session->user_id() | |
); | |
} | |
else { |
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 | |
// Query with no Active Record | |
$query = "SELECT questions.* FROM assessments LEFT JOIN questions ON assessments.id=questions.assessment_id WHERE assessments.id=4"; | |
// Query with ORM (Idiorm) | |
ORM::for_table('assessments') | |
->select('questions.*') | |
->join('questions',array('assessments.id','=','questions.assessment_id')) | |
->where('assessments.id',4) |
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 | |
// No model, but ORM | |
if ($assessment->startdate > $now || $assessment->enddate < $now)) { | |
// Assessment is expired | |
} | |
// Model and ORM, example | |
if ($assessment->expired_at_date($now)) { | |
// Assessment is expired |
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 | |
// Without ORM | |
$forum_id = 0; | |
$query = "select id from imas_forums where courseid = ".$_GET['courseid']; | |
$result = mysql_query($query) or die("Query failed: ".mysql_error()); | |
$foro = mysql_fetch_row($result); | |
if(count($foro)>0) | |
$forum_id = $foro[0]; |
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 | |
// Comenzar la sesión | |
session_start(); | |
// revisar que el array exista | |
if (!is_array($_SESSION['comentarios'])) { | |
$_SESSION['comentarios'] = array(); | |
} | |
$dato = $_POST['TxtboxCmtar']; |
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 | |
mysql_connect('localhost','root',''); | |
mysql_select_db('test'); | |
mysql_query("CREATE TABLE IF NOT EXISTS comentarios (id INT(11) NOT NULL AUTO_INCREMENT, comment TEXT, fecha TIMESTAMP, PRIMARY KEY(id))"); | |
$dato = $_POST['TxtboxCmtar']; | |
if (validar_usuario() && es_texto($dato)) { // En PHP, para comprobar una cadena, generalmente esa cadena es enviada a una función, como argumento |
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 Collection extends ArrayIterator { | |
public function map ($closure=FALSE) { | |
$copy = $this->getArrayCopy(); | |
if (is_string($closure)) { | |
$copy = array_map(function($value)use($closure){ | |
$function = function(){}; | |
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 Album < ActiveRecord::Base | |
has_many :images | |
belongs_to :gallery, :polymorphic => true | |
attr_accessible :title | |
end |