Translate,Models..
This commit is contained in:
parent
fe10b02c33
commit
8c478f4b9c
11 changed files with 161 additions and 55 deletions
|
|
@ -23,11 +23,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
return $navigation;
|
||||
}
|
||||
|
||||
protected function _initConfig()
|
||||
{
|
||||
return new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
|
||||
}
|
||||
|
||||
/**
|
||||
* View and Layout configuration
|
||||
*
|
||||
|
|
@ -35,13 +30,12 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
*/
|
||||
protected function _initView()
|
||||
{
|
||||
$this->bootstrap('config');
|
||||
|
||||
$view = new Zend_View();
|
||||
$view->setEncoding('UTF-8');
|
||||
|
||||
// Set site title
|
||||
$view->headTitle($this->getResource('config')->app->name);
|
||||
// Set site title from application.ini
|
||||
$config = $this->getApplication()->getOptions();
|
||||
$view->headTitle($config['app']['name']);
|
||||
|
||||
$layout = Zend_Layout::startMvc();
|
||||
$layout->setLayoutPath(APPLICATION_PATH . '/modules/default/views/layout');
|
||||
|
|
@ -58,12 +52,17 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
*/
|
||||
protected function _initFront()
|
||||
{
|
||||
$this->bootstrap('autoloader');
|
||||
|
||||
// Get front controller
|
||||
$frontController = Zend_Controller_Front::getInstance();
|
||||
|
||||
// Set modules directory
|
||||
$frontController->addModuleDirectory(APPLICATION_PATH . '/modules');
|
||||
|
||||
// Add plugins
|
||||
$frontController->registerPlugin(new Fiktiv_Controller_Plugin_Language());
|
||||
|
||||
return $frontController;
|
||||
}
|
||||
|
||||
|
|
@ -94,6 +93,55 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
return $router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure global and local(modules) models
|
||||
*/
|
||||
protected function _initModels()
|
||||
{
|
||||
$this->bootstrap('autoloader');
|
||||
|
||||
// Include global model directory
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
APPLICATION_PATH . '/models',
|
||||
get_include_path()
|
||||
)));
|
||||
|
||||
// Let our model autoloader plugin handle local models
|
||||
$front = $this->getResource('front');
|
||||
$front->registerPlugin(new Fiktiv_Controller_Plugin_ModelAutoloader());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure autoloader
|
||||
*
|
||||
* @return Zend_Loader_Autoloader $autoloader
|
||||
*/
|
||||
protected function _initAutoloader()
|
||||
{
|
||||
$autoloader = Zend_Loader_Autoloader::getInstance();
|
||||
$autoloader->registerNamespace('Fiktiv_');
|
||||
$autoloader->setFallbackAutoloader(true);
|
||||
|
||||
return $autoloader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure multilanguage (translator)
|
||||
*
|
||||
* @return Zend_Translate $translate
|
||||
*/
|
||||
protected function _initTranslate()
|
||||
{
|
||||
|
||||
$translate = new Zend_Translate('ini', APPLICATION_PATH . '/languages/se.ini', 'sv');
|
||||
$translate->addTranslation(APPLICATION_PATH . '/languages/en.ini', 'en');
|
||||
|
||||
Zend_Form::setDefaultTranslator($translate);
|
||||
|
||||
return $translate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a sweet and simple database
|
||||
* connection.
|
||||
|
|
|
|||
2
application/languages/en.ini
Normal file
2
application/languages/en.ini
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
USER_AGE = "Hej %s, du är %s år"
|
||||
cookie = kaka
|
||||
2
application/languages/se.ini
Normal file
2
application/languages/se.ini
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
USER_AGE = "Hej %s, du är %s år"
|
||||
cookie = kaka
|
||||
6
application/models/MyModel.php
Normal file
6
application/models/MyModel.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class MyModel
|
||||
{
|
||||
public $name = 'My Global Model';
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ class Blog_IndexController extends Zend_Controller_Action
|
|||
{
|
||||
public function indexAction()
|
||||
{
|
||||
|
||||
$m = new MyModel();
|
||||
echo $m->name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ class IndexController extends Zend_Controller_Action
|
|||
public function indexAction()
|
||||
{
|
||||
// Here be dragons
|
||||
$m = new MyModel();
|
||||
echo $m->name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
6
application/modules/default/models/MyModel.php
Normal file
6
application/modules/default/models/MyModel.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class MyModel
|
||||
{
|
||||
public $name = 'My Local Model';
|
||||
}
|
||||
|
|
@ -1,53 +1,24 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<?=$this->headTitle()."\n" /* Newline for pretty source :) */ ?>
|
||||
<meta content="description"></meta>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$this->baseUrl()?>/css/default.css" media="screen" />
|
||||
</head>
|
||||
<body>
|
||||
<head>
|
||||
<?=$this->headTitle()."\n" /* Newline for pretty source :) */ ?>
|
||||
<meta content="description"></meta>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$this->baseUrl()?>/css/default.css" media="screen" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="header">
|
||||
<div id="header"></div>
|
||||
|
||||
</div>
|
||||
<div id="nav">
|
||||
<?=$this->navigation() ?>
|
||||
<span class="float-right">
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div id="nav">
|
||||
<br/>
|
||||
|
||||
<?=$this->navigation() ?>
|
||||
<?=$this->layout()->content ?>
|
||||
|
||||
<span class="float-right">
|
||||
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
||||
<form>
|
||||
<fieldset>
|
||||
<label for="t1">Text</label>
|
||||
<input type="text" id="t1" /><br />
|
||||
<label for="ta1">Areaaaa</label>
|
||||
<textarea id="ta1"></textarea><br />
|
||||
<input type="submit" />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>abc</th>
|
||||
<th>bab</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>abc</td>
|
||||
<td>bbb</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<?=$this->layout()->content ?>
|
||||
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1 +1,29 @@
|
|||
Do nothing!
|
||||
Do nothing!
|
||||
|
||||
<?php
|
||||
|
||||
echo $this->translate('cookie');
|
||||
|
||||
?>
|
||||
|
||||
<form>
|
||||
<fieldset>
|
||||
<label for="t1">Text</label>
|
||||
<input type="text" id="t1" /><br />
|
||||
<label for="ta1">Areaaaa</label>
|
||||
<textarea id="ta1"></textarea><br />
|
||||
<input type="submit" />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>abc</th>
|
||||
<th>bab</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>abc</td>
|
||||
<td>bbb</td>
|
||||
</tr>
|
||||
</table>
|
||||
19
library/Fiktiv/Controller/Plugin/Language.php
Normal file
19
library/Fiktiv/Controller/Plugin/Language.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin to handle language shifts
|
||||
*/
|
||||
class Fiktiv_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
|
||||
$translate = $bootstrap->getResource('translate');
|
||||
|
||||
$lang = $request->getParam('lang');
|
||||
|
||||
if ($translate->isAvailable($lang)) {
|
||||
$translate->setLocale($lang);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
20
library/Fiktiv/Controller/Plugin/ModelAutoloader.php
Normal file
20
library/Fiktiv/Controller/Plugin/ModelAutoloader.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
require_once 'Zend/Controller/Plugin/Abstract.php';
|
||||
|
||||
/**
|
||||
* Auto add module model directory to include_path
|
||||
*/
|
||||
class Fiktiv_Controller_Plugin_ModelAutoloader extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request) {
|
||||
|
||||
$front = Zend_Controller_Front::getInstance();
|
||||
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
$front->getModuleDirectory() . '/models',
|
||||
get_include_path()
|
||||
)));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in a new issue