zend framework 1.12 menjalankan di folder localhost dan menghilangkan nama folder public

Alhamdulilah bagi-bagi ilmu gan, menjalankan web dengan framework zf 1 dengan memanggil folder project localhost tanpa tulisan public, adapun pengaturan yang perlu di sesuaikan yakni file index.php dan htaccess yang berada di direktori public, di pindahkan ke folder root.

Kemudian sesuaikan isi file-file tersebut menjadi seperti dibawah.

index.php

<?php

// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

//
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Registry.php';
require_once 'Zend/Db.php';
require_once 'Zend/Db/Table/Abstract.php';
require_once 'Zend/Filter/Input.php';

// get params db from application.ini
$config = new Zend_Config_Ini('application/configs/application.ini', 'db');

// set database configuration parameters
$adapter = $config->db->adapter;
$params = $config->db->params;

// initialize database
$db = Zend_Db::factory($adapter, $params);

// set database as default
Zend_Db_Table_Abstract::setDefaultAdapter($db);

// save database object in Zend_Registry
Zend_Registry::set('db', $db);

// get params db1 from application.ini
$config = new Zend_Config_Ini('application/configs/application.ini', 'db1');

// set database configuration parameters
$adapter = $config->db1->adapter;
$params = $config->db1->params;

// initialize database
$db1 = Zend_Db::factory($adapter, $params);

// set database as default
Zend_Db_Table_Abstract::setDefaultAdapter($db1);

// save database object in Zend_Registry
Zend_Registry::set('db1', $db1);

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);

$application->bootstrap()
->run();

.htaccess

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
RewriteRule ^(.*)$ - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

untuk mendefinisikan alamat utama agar dapat digunakan untuk tautan dan penglokasian asset. tambahkan helper mainUrl(); untuk mendefinisikan lokasi utama.

<?php
class Zend_View_Helper_MainUrl extends Zend_View_Helper_Abstract
{

function __construct()
{
$fc = Zend_Controller_Front::getInstance();
}

function MainUrl()
{
$str = "http://" . $_SERVER['SERVER_NAME'] . "/fingercenter-test/";
return $str;
}

}

kemudian coba panggil alamat url localhost/namafolder/, tanpa menuliskan nama folder public.

semoga bermanfaat wassalam.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s