Skip to content

Instantly share code, notes, and snippets.

function autosave(last)
{
if (typeof t!="undefined") {clearTimeout(t);} // reset timer
var data = new Object();
var interests = new Object();
var interestscount = 0;
$('#myform input,#myform textarea,#myform select').each(function(index) {
if ($(this).is(':submit')){
// ignore submit buttons
} else {
<form method="post" id="myform" action="/saveform">
Name: <input name="name" type="text" value="" /><br />
Address: <textarea name="address"></textarea><br />
Gender: <select name="gender">
<option value="M">Male</option>
<option value="F">Female</option>
</select><br />
Interests:<br />
1: <input name="interests[]" type="text" value="" /><br />
2: <input name="interests[]" type="text" value="" /><br />
$.ajax(
{
type: "POST",
url: "/ajax/autosave",
data: data,
cache: false,
success: function(message)
{
if (message == '1'){ // show success saved
t = setTimeout("autosave()", 60000); // set timer for next autosave
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('date');
$this->load->model('Users','',TRUE);
}
function index()
{
// Find all members, limit by 5, order by date
$members = $this->Users->getAll(5,array('date' => -1));
$data = array(
'members' => array()
);
while($members->hasNext()){ // While we have results
$member = $members->getNext();// Get the next result
$data['members'][] = array(
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users extends CI_Model {
function __construct() {
parent::__construct();
$tableName = 'users';
$primaryKey = 'id';
// Connect to Mongo
$this->connection = new Mongo('localhost:27017');
<?php
if(count($members) > 0):
foreach($members as $member => $fields):?>
<h1><a href="<?php echo site_url(array('welcome','view', $fields['id'])); ?>"><?php echo $fields['name']; ?></a>
<a href="<?php echo site_url(array('welcome','edit', $fields['id'])); ?>" style="font-size:12px;">Edit</a>
<a href="<?php echo site_url(array('welcome','delete', $fields['id'])); ?>" style="font-size:12px;">Delete</a></h1>
<p><?php echo ($fields['address']); ?><br />
<em>Phone: <?php echo $fields['phone']; ?><br />
Added on <?php echo unix_to_human( $fields['date'] ); ?></em></p>
<hr />
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Model extends CI_Model {
/** Set this to the table name that the model is mapped to */
protected $tableName;
/** Set this to the primary key of the table for this model.*/
protected $primaryKey;
function __construct() {
parent::__construct();
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cms extends CMS_Controller {
public function index()
{
$this->load->model('Example','',TRUE);
$allRecords = $this->Example->getAll();
$idOne = $this->Example->getById(1);
$data = array(
<?php
if ($allRecords->num_rows() > 0)
{?>
<table cellpadding="4">
<tr>
<td>Name</td>
<td>Email</td>
<td>Phone</td>
</tr>
<?php