PHP code example of takuya-motoshima / codeigniter-extension

1. Go to this page and download the library: Download takuya-motoshima/codeigniter-extension library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

takuya-motoshima / codeigniter-extension example snippets


use \X\Annotation\Access;

class Users extends AppController {

  /** @Access(allow_login=true, allow_logoff=false, allow_role="admin") */
  public function index() {
    $users = $this->UserModel->get()->result_array();
    parent::set('users', $users)->view('users/index');
  }

  /** @Access(allow_http=true) */
  public function api() {
    parent::set(['message' => 'Success'])->json();
  }
}

class UserModel extends AppModel {
  const TABLE = 'user';

  public function getActiveUsers() {
    return $this
      ->where('active', 1)
      ->order_by('name', 'ASC')
      ->get()
      ->result_array();
  }
}

use \X\Util\{ImageHelper, FileHelper, Cipher, RestClient};

// Image
ImageHelper::resize('/path/to/image.jpg', '/path/to/output.jpg', 800, 600);

// Files
FileHelper::makeDirectory('/path/to/dir', 0755);

// Encryption
$encrypted = Cipher::encrypt('secret data', 'encryption-key');

// REST
$client = new RestClient(['base_url' => 'https://api.example.com']);
$response = $client->get('/users');

use \X\Annotation\AnnotationReader;
use \X\Util\Logger;

$hook['post_controller_constructor'] = function() {
  if (is_cli()) return;

  $CI =& get_instance();
  $meta = AnnotationReader::getAccessibility($CI->router->class, $CI->router->method);
  $loggedin = !empty($_SESSION[SESSION_NAME]);

  if (!$meta->allow_http)
    throw new \RuntimeException('HTTP access is not allowed');
  else if ($loggedin && !$meta->allow_login)
    redirect('/users/index');
  else if (!$loggedin && !$meta->allow_logoff)
    redirect('/users/login');
};

$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'session';
$config['sess_table_additional_columns'] = ['email'];
sh
sudo dnf -y install ImageMagick ImageMagick-devel php-pear.noarch
sudo pecl install imagick
echo "extension=imagick.so" | sudo tee -a /etc/php.ini
sudo systemctl restart nginx php-fpm