
RewriteEngine On
Options -MultiViews
RewriteBase /basitegitim
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
<?php
require_once 'cekirdek/Fonksiyonlar.php';
require_once 'cekirdek/Uygulama.php';
require_once 'cekirdek/Kontroller.php';
//require_once 'veritabani/Db.class.php';
<?php
class FN {
public function __construct() {
}
public static function haftanin_kacinci_gunu() {
$hafta = date('w');
$hafta == 0 ? $hafta = 7 : null;
return $hafta;
}
}
<?php
class Uygulamalar {
protected $kontroller = 'ev';
protected $metod = 'index';
protected $parametre = [];
public function __construct() {
$url = $this->parseUrl();
if (isset($url[0])) {
if (file_exists('uygulama/kontroller/' . $url[0] . '.php')) {
$this->kontroller = $url[0];
unset($url[0]);
}
}
require_once 'uygulama/kontroller/' . $this->kontroller . '.php';
$this->kontroller = new $this->kontroller;
if (isset($url[1])) {
if (method_exists($this->kontroller, $url[1])) {
$this->metod = $url[1];
unset($url[1]);
}
}
$this->parametre = $url ? array_values($url) : [];
call_user_func_array([$this->kontroller, $this->metod], $this->parametre);
}
public function parseUrl() {
// isset böyle bir nesne varmı ? diye kontrol eder
if (isset($_GET["url"])) {
return $url = explode('/', filter_var(rtrim($_GET["url"], '/'), FILTER_SANITIZE_URL));
}
}
}
Dikkat edilmesi gereken yer Çekirdek klasörünün içindeki "kontroller.php" ile "Kontroller" klasörünün karıştırılmamasıdır.
Çekirdek->kontroller.php dosyasının içeriği =>
<?php
class Kontroller {
public function model($model) {
require_once 'uygulama/modeller/' . $model . '.php';
return new $model();
}
public function goruntu($goruntu, $veri = [], $sayfa = "ana") {
if ($sayfa == "ana") {
require_once 'uygulama/goruntuler/sabitler/ust.php';
require_once 'uygulama/goruntuler/sabitler/ustmenu.php';
require_once 'uygulama/goruntuler/' . $goruntu . '.php';
require_once 'uygulama/goruntuler/sabitler/alt.php';
} else if ($sayfa == "giris") {
require_once 'uygulama/goruntuler/sabitler/ust.php';
require_once 'uygulama/goruntuler/' . $goruntu . '.php';
require_once 'uygulama/goruntuler/sabitler/alt.php';
}else if($sayfa=="tek"){
require_once 'uygulama/goruntuler/' . $goruntu . '.php';
}
}
}
settings.ini.php
;<?php return; ?>
[SQL]
host = localhost
user = root
password =
dbname = okulumx
Db.class.php
<?php
/**
* DB - A simple database class
*
* @author Author: Vivek Wicky Aswal. (https://twitter.com/#!/VivekWickyAswal)
* @git https://github.com/wickyaswal/PHP-MySQL-PDO-Database-Class
* @version 0.2ab
*
*/
require("Log.class.php");
class DB
{
# @object, The PDO object
private $pdo;
# @object, PDO statement object
private $sQuery;
# @array, The database settings
private $settings;
# @bool , Connected to the database
private $bConnected = false;
# @object, Object for logging exceptions
private $log;
# @array, The parameters of the SQL query
private $parameters;
/**
* Default Constructor
*
* 1. Instantiate Log class.
* 2. Connect to database.
* 3. Creates the parameter array.
*/
public function __construct()
{
$this->log = new Log();
$this->Connect();
$this->parameters = array();
}
/**
* This method makes connection to the database.
*
* 1. Reads the database settings from a ini file.
* 2. Puts the ini content into the settings array.
* 3. Tries to connect to the database.
* 4. If connection failed, exception is displayed and a log file gets created.
*/
private function Connect()
{
$this->settings = parse_ini_file("settings.ini.php");
$dsn = 'mysql:dbname=' . $this->settings["dbname"] . ';host=' . $this->settings["host"] . '';
try {
# Read settings from INI file, set UTF8
$this->pdo = new PDO($dsn, $this->settings["user"], $this->settings["password"], array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));
# We can now log any exceptions on Fatal error.
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Disable emulation of prepared statements, use REAL prepared statements instead.
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
# Connection succeeded, set the boolean to true.
$this->bConnected = true;
}
catch (PDOException $e) {
# Write into log
echo $this->ExceptionLog($e->getMessage());
die();
}
}
/*
* You can use this little method if you want to close the PDO connection
*
*/
public function CloseConnection()
{
# Set the PDO object to null to close the connection
# http://www.php.net/manual/en/pdo.connections.php
$this->pdo = null;
}
/**
* Every method which needs to execute a SQL query uses this method.
*
* 1. If not connected, connect to the database.
* 2. Prepare Query.
* 3. Parameterize Query.
* 4. Execute Query.
* 5. On exception : Write Exception into the log + SQL query.
* 6. Reset the Parameters.
*/
private function Init($query, $parameters = "")
{
# Connect to database
if (!$this->bConnected) {
$this->Connect();
}
try {
# Prepare query
$this->sQuery = $this->pdo->prepare($query);
# Add parameters to the parameter array
$this->bindMore($parameters);
# Bind parameters
if (!empty($this->parameters)) {
foreach ($this->parameters as $param => $value) {
if(is_int($value[1])) {
$type = PDO::PARAM_INT;
} else if(is_bool($value[1])) {
$type = PDO::PARAM_BOOL;
} else if(is_null($value[1])) {
$type = PDO::PARAM_NULL;
} else {
$type = PDO::PARAM_STR;
}
// Add type when binding the values to the column
$this->sQuery->bindValue($value[0], $value[1], $type);
}
}
# Execute SQL
$this->sQuery->execute();
}
catch (PDOException $e) {
# Write into log and display Exception
echo $this->ExceptionLog($e->getMessage(), $query);
die();
}
# Reset the parameters
$this->parameters = array();
}
/**
* @void
*
* Add the parameter to the parameter array
* @param string $para
* @param string $value
*/
public function bind($para, $value)
{
$this->parameters[sizeof($this->parameters)] = [":" . $para , $value];
}
/**
* @void
*
* Add more parameters to the parameter array
* @param array $parray
*/
public function bindMore($parray)
{
if (empty($this->parameters) && is_array($parray)) {
$columns = array_keys($parray);
foreach ($columns as $i => &$column) {
$this->bind($column, $parray[$column]);
}
}
}
/**
* If the SQL query contains a SELECT or SHOW statement it returns an array containing all of the result set row
* If the SQL statement is a DELETE, INSERT, or UPDATE statement it returns the number of affected rows
*
* @param string $query
* @param array $params
* @param int $fetchmode
* @return mixed
*/
public function query($query, $params = null, $fetchmode = PDO::FETCH_ASSOC)
{
$query = trim(str_replace("\r", " ", $query));
$this->Init($query, $params);
$rawStatement = explode(" ", preg_replace("/\s+|\t+|\n+/", " ", $query));
# Which SQL statement is used
$statement = strtolower($rawStatement[0]);
if ($statement === 'select' || $statement === 'show') {
return $this->sQuery->fetchAll($fetchmode);
} elseif ($statement === 'insert' || $statement === 'update' || $statement === 'delete') {
return $this->sQuery->rowCount();
} else {
return NULL;
}
}
/**
* Returns the last inserted id.
* @return string
*/
public function lastInsertId()
{
return $this->pdo->lastInsertId();
}
/**
* Starts the transaction
* @return boolean, true on success or false on failure
*/
public function beginTransaction()
{
return $this->pdo->beginTransaction();
}
/**
* Execute Transaction
* @return boolean, true on success or false on failure
*/
public function executeTransaction()
{
return $this->pdo->commit();
}
/**
* Rollback of Transaction
* @return boolean, true on success or false on failure
*/
public function rollBack()
{
return $this->pdo->rollBack();
}
/**
* Returns an array which represents a column from the result set
*
* @param string $query
* @param array $params
* @return array
*/
public function column($query, $params = null)
{
$this->Init($query, $params);
$Columns = $this->sQuery->fetchAll(PDO::FETCH_NUM);
$column = null;
foreach ($Columns as $cells) {
$column[] = $cells[0];
}
return $column;
}
/**
* Returns an array which represents a row from the result set
*
* @param string $query
* @param array $params
* @param int $fetchmode
* @return array
*/
public function row($query, $params = null, $fetchmode = PDO::FETCH_ASSOC)
{
$this->Init($query, $params);
$result = $this->sQuery->fetch($fetchmode);
$this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
return $result;
}
/**
* Returns the value of one single field/column
*
* @param string $query
* @param array $params
* @return string
*/
public function single($query, $params = null)
{
$this->Init($query, $params);
$result = $this->sQuery->fetchColumn();
$this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued
return $result;
}
/**
* Writes the log and returns the exception
*
* @param string $message
* @param string $sql
* @return string
*/
private function ExceptionLog($message, $sql = "")
{
$exception = 'Unhandled Exception. <br />';
$exception .= $message;
$exception .= "<br /> You can find the error back in the log.";
if (!empty($sql)) {
# Add the Raw SQL to the Log
$message .= "\r\nRaw SQL : " . $sql;
}
# Write into log
$this->log->write($message);
return $exception;
}
}
?>
Log.class.php
<?php
/* *
* Log A logger class which creates logs when an exception is thrown.
* @author Author: Vivek Wicky Aswal. (https://twitter.com/#!/VivekWickyAswal)
* @git https://github.com/wickyaswal/PHP-MySQL-PDO-Database-Class
* @version 0.1a
*/
class Log {
# @string, Log directory name
private $path = '/logs/';
# @void, Default Constructor, Sets the timezone and path of the log files.
public function __construct() {
date_default_timezone_set('Europe/Amsterdam');
$this->path = dirname(__FILE__) . $this->path;
}
/**
* @void
* Creates the log
*
* @param string $message the message which is written into the log.
* @description:
* 1. Checks if directory exists, if not, create one and call this method again.
* 2. Checks if log already exists.
* 3. If not, new log gets created. Log is written into the logs folder.
* 4. Logname is current date(Year - Month - Day).
* 5. If log exists, edit method called.
* 6. Edit method modifies the current log.
*/
public function write($message) {
$date = new DateTime();
$log = $this->path . $date->format('Y-m-d').".txt";
if(is_dir($this->path)) {
if(!file_exists($log)) {
$fh = fopen($log, 'a+') or die("Fatal Error !1");
$logcontent = "Time : " . $date->format('H:i:s')."\r\n" . $message ."\r\n";
fwrite($fh, $logcontent);
fclose($fh);
}
else {
$this->edit($log,$date, $message);
}
}
else {
if(mkdir($this->path,0777) === true)
{
$this->write($message);
}
}
}
/**
* @void
* Gets called if log exists.
* Modifies current log and adds the message to the log.
*
* @param string $log
* @param DateTimeObject $date
* @param string $message
*/
private function edit($log,$date,$message) {
$logcontent = "Time : " . $date->format('H:i:s')."\r\n" . $message ."\r\n\r\n";
$logcontent = $logcontent . file_get_contents($log);
file_put_contents($log, $logcontent);
}
}
?>
modeller->Uyeler.php =>
<?php
class Uyeler {
protected $db = [];
public $veri = [];
public function __construct() {
$this->db = new DB();
}
public function tum_uyeler() {
$veri_al = $this->db->query("select * from uyeler");
$this->veri["uyeler"] = $veri_al;
}
}
kontroller->kullanicilar.php
<?php
class Kullanicilar extends Kontroller {
public function __construct() {
}
public function isim($id = "") {
$model = $this->model("Uyeler");
$model->tum_uyeler();
$uyeler = $model->veri["uyeler"];
$this->goruntu('uyeler/listele', ["ad" => $uyeler], "giris");
}
}
Yazılım dilini öğrenmenin en etiki yolu "PROJE" üzerinden ilerlemektir!
Php'nin tüm özellikleri anlatmaya kalksak haftalarımızı alır. Bu yüzden bir projede ihtiyacımız olan kısımları yeri gelindiğinde detaylı ve örneklerle ele alarak anlatacağız.
Bu kursta gerçek bir projeyi adım adım ilerleyerek detaylara girerek anlatacağız.
Özel okul ve kurslarda öğrencilerimize uyguladığımız yöntemleri daha detaylı ve açıklayıcı olacak şekilde burada anlatacağız.
Bazı kalıpların akılda kalması için görsellere ve hayattan örneklere yer vereceğiz.
Kod mimarisini oluştururken en çok nasıl performans elde ederiz diyeceğiz.
Başlangıç düzeyinizde herhangi bir dilde alt yapınız varsa bu eğitim serisinde hiç zorlanmadan ilerleyebileceksiniz.
Kendinize ait blog sayfası nasıl oluşturulur bunu anlatacağız.
Başlangıç seviyesi olan düzeyinizi bulutların üzerine çıkartacaz.
Burada öğreneceğiniz alp yapı ile ileriye dönük çok büyük projeleri tasarlayabileceksiniz.
Kendimize ait PHP framework sistemi kurup projeleri çok hızlı büyüteceğiz.
Not: Kendimize ait "framework" ne demek ?
Aradan yıllar geçse bile sisteme bir şey eklemek istediğinizde hiç zorlanmadan neyi nereye eklemeniz gerektiğini bilmenizi sağlar.
Herhangi bir problemin tek bakışta nerede oluştuğunu gösterir.
Birden fazla kişiyle tek projeyi rahatlıkla yürütebilir.
Modüler yapısı sayesinde A projesinde hazırladığınız bi modülü tek hareketle B projesinde kullanabilir.
Burada öğreneceğimiz sistemleri aradan uzun süreler geçse bile rahatlıkla anlayıp güncelleme işlemleri yapabileceğiz.
Kursun İlerleyişi;
Php dilinde kod yazabilmek için gerekli programın kurulması.
Kodları rahat ve anlaşılır yazabilmek için gelişmiş metin editörü kurulumu.
Ücretsiz lisanslı tema indirmek.
Temayı kendimize göre türkçeleştirmek ve gerekli alanların çıkartılıp değiştirilmesi.
Sayfa parçalarına ayırmak.
Php framework yapısının kurulması ve detaylı anlatılması
Sayfanın bölümlerinin gerekli php sayfalarına aktarılması.
Kontrol panelinin giriş sayfasının tasarlanması.
Kontrol panelinde yapılabileceklerin belirlenmesi ve tasarlanamsı(Yazı ekleme, Silme, Güncelleme)
İstatistik sayfasının tasarlanması(Sayfa kaç gez görüntülendi, yazı kaç kez okundu.)
Panelden eklediğimiz yazıların bloğumuzda uygun yerde görüntülenmesi.
Bir blok yazısının kendisine ait özel sayfada incelenmesi
Projeyi gerçek sunucuya yükleme ve yayınlamak.
Php ve javascript ile dans etmeye hazır mısınız?