Friday, July 22, 2016

004 Yii dengan database

1.create database dan table dg isi:

CREATE TABLE `country` (
  `code` CHAR(2) NOT NULL PRIMARY KEY,
  `name` CHAR(52) NOT NULL,
  `population` INT(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `country` VALUES ('AU','Australia',24016400);
INSERT INTO `country` VALUES ('BR','Brazil',205722000);
INSERT INTO `country` VALUES ('CA','Canada',35985751);
INSERT INTO `country` VALUES ('CN','China',1375210000);
INSERT INTO `country` VALUES ('DE','Germany',81459000);
INSERT INTO `country` VALUES ('FR','France',64513242);
INSERT INTO `country` VALUES ('GB','United Kingdom',65097000);
INSERT INTO `country` VALUES ('IN','India',1285400000);
INSERT INTO `country` VALUES ('RU','Russia',146519759);
INSERT INTO `country` VALUES ('US','United States',322976000);

koneksi di config/db.php


return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=yii2basic',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
];

model dibuat dulu (models/Country.php), diturunkan dari ActiveRecord:


namespace frontend\models;

use yii\db\ActiveRecord;

class Country extends ActiveRecord
{
}


 action dibuat di controller sendiri (country/CountryController.php):


namespace frontend\controllers;

use yii\web\Controller;
use yii\data\Pagination;
use frontend\models\Country;

class CountryController extends Controller
{
    public function actionIndex()
    {
        $query = Country::find();

        $pagination = new Pagination([
            'defaultPageSize' => 5,
            'totalCount' => $query->count(),
        ]);

        $countries = $query->orderBy('name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();

        return $this->render('index', [
            'countries' => $countries,
            'pagination' => $pagination,
        ]);
    }
}

buat view di views/country/index.php


namespace frontend\controllers;

use yii\web\Controller;
use yii\data\Pagination;
use frontend\models\Country;

class CountryController extends Controller
{
    public function actionIndex()
    {
        $query = Country : : find();

        $pagination = new Pagination([
            'defaultPageSize' => 5,
            'totalCount' => $query->count(),
        ]);

        $countries = $query->orderBy('name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();

        return $this->render('index', [
            'countries' => $countries,
            'pagination' => $pagination,
        ]);
    }
}

coba : http://hostname/index.php?r=country%2Findex




Thursday, July 21, 2016

003 Create form input

Goal : form input  - menerima data dari user - tampilkan lagi utk konfirmasi

1.buat model, dg variable public name dan email
ada rule name, email yg required dan email yg benar


namespace frontend\models;

use Yii;
use yii\base\Model;

class EntryForm extends Model
{
    public $name;
    public $email;

    public function rules()
    {
        return [
            [['name', 'email'], 'required'],
            ['email', 'email'],
        ];
    }
}

2. buat action di siteController

    public function actionEntry()
    {
        $model = new EntryForm();

        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            // valid data received in $model

            // do something meaningful here about $model ...

            return $this->render('entry-confirm', ['model' => $model]);
        } else {
            // either the page is initially displayed or there is some validation error
            return $this->render('entry', ['model' => $model]);
        }
    }

tampak di sana ada 2 view = entry dan entry-confirm

use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>


field($model, 'name')->label('Your Name') ?>
field($model, 'email')->label('Your Email') ?>

   

        'btn btn-primary']) ?>
   


ActiveForm menghandle dengan baik, perhatikan begin() dan end()

utk entry-confirm:

use yii\helpers\Html;
?>
You have entered the following information:



       
  • : name) ?>

  •    
  • : email) ?>






Wednesday, July 20, 2016

002 Create Action

Action = object yg bisa di eksekusi oleh end-user
- di group/masuk dlm controller (misal site controller)
cara nulis, contoh : action[nama action nya dimulai huruf besar]
  actionSay
  actionCreateComment


namespace app\controllers;

use yii\web\Controller;

class SiteController extends Controller
{
    // ...existing code...

    public function actionSay($message = 'Hello')
    {
        return $this->render('say', ['message' => $message]);
    }
}

 fungsi render = memanggil view di parameter ke 1, berarti file 'say'
file view disimpan di views/site/say.php

maka header dan footer akan tetap sama, isinya yg berubah
tampilan diambil dari : views/layouts/main.php

kalau Controller cara nulisnya : namaController, contoh : siteController.php


001 Install Yii versi 2

composer = management tool utk dependency, jadi bisa install dependency otomatis bila tidak ada.

install dari yii-advanced-app-2.0.9.tgz

extract

copy semua ke folder www

buka cmd, jalankan = php         init
contoh:
/xampp/php/php.exe        /Users/user/Documents/www/yii2/yii-advanced-app-2.0.9/advanced/init

pilih dev

create database, konfigure dbname dan password di common/config/main-local.php

isi di \xampp\apache\conf\extra\httpd-vhosts.conf


  
       ServerName frontend.dev
       DocumentRoot "/path/to/yii-application/frontend/web/"

      
           # use mod_rewrite for pretty URL support
           RewriteEngine on
           # If a directory or a file exists, use the request directly
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           # Otherwise forward the request to index.php
           RewriteRule . index.php

           # use index.php as index file
           DirectoryIndex index.php

           # ...other settings...
      

  


  
       ServerName backend.dev
       DocumentRoot "/path/to/yii-application/backend/web/"

      
           # use mod_rewrite for pretty URL support
           RewriteEngine on
           # If a directory or a file exists, use the request directly
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           # Otherwise forward the request to index.php
           RewriteRule . index.php

           # use index.php as index file
           DirectoryIndex index.php

           # ...other settings...
      

  


restart apache, run : http://frontend.dev
ada 2 webroot: http://frontend.dev dan http://backend.dev


Friday, June 17, 2016

auto login lxde debian

nano /etc/lightdm/lightdm.conf
#autologin-user=

remove #, menjadi
autologin-user=


Moung iso file debian wheezy as local repository

mkdir /isoimage/
mount -t iso9660 -o ro,loop /root/Desktop/debian1.iso /isoimage
mkdir -p /media/debian
cp /isoimage/* -R /media/debian/
umount /isoimage

nano /etc/apt/sources.list
deb file:/media/debian/ wheezy main contrib


Tuesday, January 19, 2016

Sunday, August 9, 2015

PHP Online edit file

 <?php  
   
 // configuration  
 $url = 'http://[domain]/editor.php';  
 $dir = '/[path to file]/';  
 $nama = 'index.php';  
   
 // check nama, call: [$url]?nama=[file to edit]  
 if (isset($_GET['nama']))  
 {  
   $nama=$_GET['nama'];  
 }  
 $file = $dir.$nama;  
   
 // check if form has been submitted  
 if (isset($_POST['text']))  
 {  
   // save the text contents  
   file_put_contents($file, $_POST['text']);  
   
   // redirect to form again  
   header(sprintf('Location: %s', $url.'?'.'nama='.$nama));  
   printf('<a href="%s">Moved</a>.', htmlspecialchars($url));  
   exit();  
 }  
   
 // read the textfile  
 $text = file_get_contents($file);  
   
 ?>  
 <!-- HTML form -->  
 <form action="" method="post">  
 <input name="nama" value="<?php echo $nama; ?>"/>  
 <textarea name="text" style="width: 100%; height:80%;"><?php echo htmlspecialchars($text) ?></textarea>  
 </br>  
 <input type="submit" />  
 <input type="reset" />  
 </form>  

Thursday, July 30, 2015

stripall.php

 <?php  
 /*  
  * menghilangkan comment di php  
  * 1.copy folder yg mau di eksekusi,misal di test  
  * 2.lalu jalankan:  
  *   php stripall.php  
  *   
  **/  
   
   
 function rmcomments($id) {  
   if (file_exists($id)) {  
     if (is_dir($id)) {  
       $handle = opendir($id);  
       while($file = readdir($handle)) {  
         if (($file != ".") && ($file != "..")) {  
           rmcomments($id."/".$file); }}  
       closedir($handle); }  
     else if ((is_file($id)) && (substr($id,-4) == ".php")) {  
       if (!is_writable($id)) { chmod($id,0777); }  
       if (is_writable($id)) {  
         $command = "php --strip " . $id . " > " . $id.".new";  
         echo $command."\n";  
         $output = shell_exec($command);  
         unlink($id);  
         rename($id.".new",$id);  
         /*  
         $fileStr = file_get_contents($id);  
         $newStr = '';  
         $commentTokens = array(T_COMMENT);  
         if (defined('T_DOC_COMMENT')) { $commentTokens[] = T_DOC_COMMENT; }  
         if (defined('T_ML_COMMENT')) { $commentTokens[] = T_ML_COMMENT; }  
         $tokens = token_get_all($fileStr);  
         foreach ($tokens as $token) {    
           if (is_array($token)) {  
             if (in_array($token[0], $commentTokens)) { continue; }  
             $token = $token[1]; }  
           $newStr .= $token; }  
         if (!file_put_contents($id,$newStr)) {  
           $open = fopen($id,"w");  
           fwrite($open,$newStr);  
           fclose($open); }  
         */  
       }  
     }}}  
   
 rmcomments("./test");  
   
 ?>  

Sunday, July 26, 2015

Install nginx php5 php5-fpm php-apc maridb on Wheezy

apt-get install -y nginx php5 php5-fpm php-apc

apt-get install python-software-properties
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
add-apt-repository 'deb http://kartolo.sby.datautama.net.id/mariadb/repo/10.0/debian wheezy main'

apt-get update
apt-get install mariadb-server

--matikan inno db
--stop dulu MySQL nya = service mysql stop

# cat > /etc/mysql/conf.d/lowendbox.cnf
[mysqld]
skip-innodb
default_storage-engine=MyISAM
(tekan ^D)

===update nginx 1.2 ke 1.6 ===
#add wheezy-backports to your /etc/apt/sources.list:
deb http://ftp.de.debian.org/debian/ wheezy-backports main contrib non-free

and then on a console:

apt-get update
apt-get -t wheezy-backports install nginx

==utk hidef = gak perlu
apt-get install -y php-pear php5-dev libcurl3-openssl-dev libpcre3-dev make
#lalu
pecl install hidef


Thursday, July 23, 2015

Squid3 on vps debian wheezy

install minimal deb 7

apt-get -y update && apt-get -y upgrade
apt-get -y install nano squid3 apache2-utils
cp /etc/squid3/squid.conf /etc/squid3/squid.conf.bak
nano /etc/squid3/squid.conf

Squid3 on vps centos 6, 64 bit min

choose vps centos 6, 64 bit minimal

yum -y update

yum install -y nano squid

mv /etc/squid/squid.conf /etc/squid/squid.ori

nano /etc/squid/squid.conf

#copy paste:

Friday, June 26, 2015

Harddisk sbg RAM

free -m

dd if=/dev/zero of=~/subinsblog bs=4096 count=262144

sudo mkswap ~/subinsblog -f && sudo swapon -p 1000 ~/subinsblog

free -m

Tuesday, June 23, 2015

ZC - JUN 2015

Beberapa data yang penting.


Thursday, May 7, 2015

Install proxmox on debian

#reinstall debian minimal 64 bit

nano /etc/hosts
#tambahkan
192.168.6.177 proxmox-6-177.proxmox.com proxmox-6-177 pvelocalhost

nano /etc/apt/sources.list
#tambahkan
deb http://ftp.at.debian.org/debian wheezy main contrib
# PVE repository provided by proxmox.com, only for installation (this repo will stay on 3.1)
deb http://download.proxmox.com/debian wheezy pve
# security updates
deb http://security.debian.org/ wheezy/updates main contrib

wget -O- "http://download.proxmox.com/debian/key.asc" | apt-key add -
apt-get update && apt-get dist-upgrade -y

apt-get install -y pve-firmware pve-kernel-2.6.32-26-pve pve-headers-2.6.32-26-pve
reboot
uname -a
#Linux ...-pve

apt-get remove linux-image-amd64 linux-image-3.2.0-4-amd64 linux-base
update-grub
apt-get install -y proxmox-ve-2.6.32 ntp ssh lvm2 postfix ksm-control-daemon vzprocps open-iscsi bootlogd

==

Wednesday, May 6, 2015

Debian min ram desktop

debian min
apt-get update -y
apt-get upgrade -y
apt-get install -y xorg lxde

Thursday, April 30, 2015

Local repository Debian

copy filedvd.iso ke /home/
mount -o loop /home/dvd.iso /mnt
cd /mnt
find pool -name "*.deb" -exec cp {} /folder_deb \;

setelah selesai, unmount
exit dulu
unmount /mnt

masuk ke /folder_deb
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
.
.
.
dpkg-scanpackages: info: Wrote 9404 entries to output Packages file

tambahkan:

deb file:/var/www/packages/i386/ /

di /etc/apt/sources.list

cek:
apt-get install mc

Tuesday, April 7, 2015

Local repository centos

copy file-iso-centos ke /root/Desktop/file.iso

mount -o loop /root/Desktop/file.iso /mnt
cd /mnt
find Packages/ -name "*.rpm* -exec cp {} /folder_repo \;

buat file:
/etc/yum.repos.d/centosdvdiso.repo

isinya:
[centosdvdiso]
name=CentOS DVD ISO
baseurl=file:///folder_repo
enabled=1
gpgcheck=0
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-6

hapus .repo yg lain di /etc/yum.repos.d/

lakukan juga utk DVD ke 2 dst

trus:
createrepo /folder_repo
----end

Saturday, February 28, 2015

dual filter

Show stocks where close is between 40 and 70
and the average day range(5) is above 3%
and the average day range(5) 10 day ago  is above 3%
and the average day range(5) 20 day ago  is above 3%
and the average day range(5) 30 day ago  is above 3%
and average volume(100) is above 2000000
and volume 10 day ago is above 1500000
and volume 15 day ago is above 1500000
and volume 20 day ago is above 1500000
and volume 25 day ago is above 1500000
and volume 30 day ago is above 1500000
and optionable

Thursday, January 29, 2015

Disable ip6 Wheezy

root:~# echo "net.ipv6.conf.all.disable_ipv6=1" >/etc/sysctl.d/disable-ipv6.conf
root:~# sysctl -p /etc/sysctl.d/disable-ipv6.conf 
 
 
 
---
root:~# vi /etc/hosts
....
# The following lines are desirable for IPv6 capable hosts
##::1     localhost ip6-localhost ip6-loopback
##ff02::1 ip6-allnodes
##ff02::2 ip6-allrouters
 
----
root:~# vi /etc/network/interfaces
....
#iface eth0 inet6 static
#  address 2001:4ba0:92f3:3:46::
#  netmask 80
#  up ip -6 route add 2001:4ba0:92f3:3::1 dev eth0
#  down ip -6 route del 2001:4ba0:92f3:3::1 dev eth0
#  up ip -6 route add default via 2001:4ba0:92f3:3::1 dev eth0
#  down ip -6 route del default via 2001:4ba0:92f3:3::1 dev eth0

root:~# service networking restart
 
----
root:~# netstat -tulpen | egrep 'tcp6|udp6'
tcp6       0      0 :::22                   :::*                    LISTEN      0          7961        -               
udp6       0      0 :::123                  :::*                                0          13790       -
 
---
root:~# vi /etc/ssh/sshd_config
....
AddressFamily inet
#ListenAddress ::
ListenAddress 0.0.0.0

root:~# service ssh restart
 
---
root:~# vi /etc/default/ntp
NTPD_OPTS='-4 -g'

root:~# service ntp restart 
 
---
root:~# netstat -tulpen | egrep 'tcp6|udp6'
 
 
kosong