Skip to content

Commit 9c28d25

Browse files
committed
fixes to system language and template
1 parent 4fe8753 commit 9c28d25

File tree

8 files changed

+39
-21
lines changed

8 files changed

+39
-21
lines changed

app/HomeController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ public function __construct (Template $template) {
1212
public function showIndex()
1313
{
1414
$msg='Welcome';
15-
$this->template->assign('page_title',$msg);
15+
$title="webdevlabs";
16+
17+
$this->template->assign([
18+
'page_title'=>$title,
19+
'page_content'=>$msg
20+
]);
1621
return $this->template->display('layout.tpl');
1722
}
1823

app/views/layout.tpl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@
3838
<div class="masthead clearfix">
3939
<div class="inner">
4040
<h3 class="masthead-brand">{$page_title}</h3>
41-
<nav>
41+
<nav>{$requestURI}
4242
<ul class="nav masthead-nav">
43-
<li class="active"><a href="#">Home</a></li>
44-
<li><a href="#features">Features</a></li>
45-
<li><a href="#contact">Contact</a></li>
43+
<li {if $requestURI eq '/'}class="active"{/if}><a href="{$BASE_URL}">Home</a></li>
44+
<li {if $requestURI eq '/admin'}class="active"{/if}><a href="{$BASE_URL}/admin">Admin</a></li>
45+
<li {if $requestURI eq '/admin/dashboard'}class="active"{/if}><a href="{$BASE_URL}/admin/dashboard">Dashboard</a></li>
46+
<li {if $requestURI eq '/test'}class="active"{/if}><a href="{$BASE_URL}/test">test</a></li>
47+
<li><a href="#">({$language})</a></li>
4648
</ul>
4749
</nav>
4850
</div>
@@ -56,19 +58,19 @@
5658
<div class="features">
5759
<dl class="dl-horizontal">
5860
<dt><a href="https://github.com/mrjgreen/phroute">Phroute</a></dt>
59-
<dd>URL Routing</dd>
61+
<dd>URL Router</dd>
6062
</dl>
6163
<dl class="dl-horizontal">
6264
<dt><a href="https://github.com/PHP-DI/PHP-DI">PHP-DI</a></dt>
6365
<dd>Dependency Injection Container</dd>
6466
</dl>
6567
<dl class="dl-horizontal">
6668
<dt><a href="https://github.com/smarty-php/smarty">Smarty</a></dt>
67-
<dd>template engine</dd>
69+
<dd>Template Engine</dd>
6870
</dl>
6971
<dl class="dl-horizontal">
7072
<dt><a href="https://github.com/tedious/www.stashphp.com">Stash</a></dt>
71-
<dd>caching library</dd>
73+
<dd>Caching Library</dd>
7274
</dl>
7375
</div>
7476
</p>
@@ -77,6 +79,10 @@
7779
</p>
7880
</div>
7981

82+
<div class="inner">
83+
<h3>{$page_content}</h3>
84+
</div>
85+
8086
<div class="mastfoot">
8187
<div class="inner">
8288
<p>Cover template for <a href="http://getbootstrap.com">Bootstrap</a>, by <a href="https://twitter.com/mdo">@mdo</a>.</p>

bootstrap.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*
1212
*/
1313

14+
error_reporting(1);
15+
1416
include __DIR__ . '/config/system.php';
1517
include __DIR__ . '/config/cache.php';
1618
include __DIR__ . '/config/database.php';
@@ -51,9 +53,9 @@
5153
$URIparts = explode("/", $requestURI);
5254
// check if language is set by url
5355
if (in_array($URIparts[1], $language->available_languages)) {
54-
$language->load($URIparts[1]);
5556
// rewrite requestURI
5657
$requestURI=after($URIparts[1],$requestURI);
58+
$language->load($URIparts[1]);
5759
}else {
5860
$language->load('default');
5961
}
@@ -71,7 +73,9 @@
7173
*/
7274
$session = $container->get('\System\Session');
7375
$session->start();
74-
76+
$session->set('admin_id',1);
77+
$session->set('requestURI',$requestURI);
78+
7579
/**
7680
* Load System \System\Modules
7781
*/

modules/admin/controllers/Dashboard.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ class Dashboard {
77
private $template;
88
public function __construct (Template $template) {
99
$this->template = $template;
10+
$this->template->assign('page_title','Admin Panel');
1011
}
1112

1213
public function anyIndex() {
1314
$msg='Welcome Admin!';
14-
$this->template->assign('page_title',$msg);
15+
$this->template->assign('page_content',$msg);
1516
return $this->template->display('layout.tpl');
1617
}
1718

1819
public function getDashboard() {
1920
$msg='Welcome Admin! This is your dashboard';
20-
$this->template->assign('page_title',$msg);
21+
$this->template->assign('page_content',$msg);
2122
return $this->template->display('layout.tpl');
2223
}
2324

modules/test/front/controllers/Main.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public function __construct (Template $template, Model $model) {
1919
public function showIndex()
2020
{
2121
$msg = $this->model->getMsg();
22-
$this->template->assign('page_title',$msg);
22+
$this->template->assign('page_title','Test title');
23+
$this->template->assign('page_content',$msg);
2324
return $this->template->display('layout.tpl');
2425
}
2526

storage/cache/stash/.gitkeep

Whitespace-only changes.

system/Language.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
namespace System;
33

44
class Language {
5-
5+
public $current;
66
public $available_languages = array('en', 'it', 'de', 'fr','bg');
77

8-
public function __construct (Config $conf, Template $template) {
8+
public function __construct (Config $conf) {
99
$this->conf = $conf;
10-
$this->template = $template;
1110
}
1211

1312
public function load ($lang='default') {
1413
if ($lang=='default') { $lang='en'; }
15-
$this->template->assign('language',$lang);
14+
$this->current = $lang;
1615
}
1716

1817
}

system/Template.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@
1111
*/
1212

1313
namespace System;
14+
use DI\Container;
1415

1516
class Template extends \Smarty {
1617
private $req;
1718
private $conf;
1819

19-
public function __construct (Config $conf) {
20+
public function __construct (Config $conf, Language $language) {
2021
parent::__construct();
2122
$this->conf = $conf;
22-
2323
$this->setCompileCheck(true); // set true to require smarty check if the template file is modified
2424
$this->force_compile = false; // set true only for debugging purposes
25-
25+
$requestURI = $_SESSION['requestURI'];
26+
$this->assign('requestURI',$requestURI);
27+
$this->assign('language',$language->current);
2628
$this->setTemplateDir(ROOT_DIR.'/App/views/')
2729
->setCompileDir(ROOT_DIR."/storage/cache/smarty")
2830
->setCacheDir(ROOT_DIR."/storage/cache/smarty")
@@ -35,7 +37,7 @@ public function __construct (Config $conf) {
3537
$this->registerPlugin('modifier', "roundmoney", array($this, 'roundmoney'));
3638
// $this->registerPlugin('modifier', "ago", 'ago');
3739
// if not logged in as admin
38-
if (!$_SESSION['admin_id'] > "0") {
40+
if (!$session->admin_id > "0") {
3941
if ($this->conf->encode_output_emails == '1') {
4042
$this->registerFilter("output", array($this, 'protect_email')); // encode email addresses
4143
}

0 commit comments

Comments
 (0)