Book Image

CodeIgniter Web Application Blueprints

Book Image

CodeIgniter Web Application Blueprints

Overview of this book

Table of Contents (16 chapters)
CodeIgniter Web Application Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating the model


There is only one model in this project, image_model.php. It contains functions specific to creating and resetting passwords.

Create the /path/to/codeigniter/application/models/image_model.php file and add the following code to it:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Image_model extends CI_Model {
  function __construct() {
    parent::__construct();
  }

  function save_image($data) {
    do {
      $img_url_code = random_string('alnum', 8); 

      $this->db->where('img_url_code = ', $img_url_code);
      $this->db->from('images');
      $num = $this->db->count_all_results();
    } while ($num >= 1);

    $query = "INSERT INTO `images` (`img_url_code`, `img_image_name`, `img_dir_name`) VALUES (?,?,?) ";
    $result = $this->db->query($query, array($img_url_code, $data['image_name'], $data['img_dir_name']));

    if ($result) {
      return $img_url_code;
    } else {
      return flase;
    }
...