DS Log
In my blog, I delve into the world of programming web technologies, Linux, Unix-like, and graphic design using free tools on Linux.
KINGCODE
KingCode Editor (ex Texty Editor) is my project developed using Java Swing. Project is still in development and in beta version. I plan to add additional features focused for PYTHON, PHP, JAVA, C, JS and BASH.
Read more ↗
VUE on Linux
In this guide, I'll walk you through the step-by-step process of setting up Vue.js on your Linux system, empowering you to create dynamic and interactive web applications. Let's harness the power of Vue.js together on the Linux platform!
Read more ↗
Symfony PHP
Dive into the world of Symfony PHP with this comprehensive introduction. In this guide, you'll learn the essential steps to create and manage posts and users, empowering you to build dynamic web applications with ease.
Read more ↗
Trying Linux from Windows
How to set up a PHP development server on Ubuntu 22.04
Text editors
List of text editors for developers.
Read more ↗
Fonts
Important fonts everyone needs to know.
Read more ↗
Try Linux from Windows
Here are some quick videos I made showing how to try out Linux Mint on Windows.
Read more ↗
Saturday, July 13, 2024
CodeIgniter - view templates
Before this tutorial, you need to take a look at this post.
In the CI controller the return string is what is displayed visually in the Internet browser.
class HelloController extends BaseController
{
public function index()
{
return "I am the text displayed in the browser!";
}
}
We call the View function to load a template (html template) from the "app/View" directory.
class HelloController extends BaseController
{
public function index()
{
return view("my-view-file.php");
}
}
Or if we have a sub-directory “app/View/header”
class HelloController extends BaseController
{
public function index()
{
return view("header/my-view-file.php");
}
}
How do we transfer data from the controller to the template?
We transfer data from the controller to the template via an associative array.
class HelloController extends BaseController
{
public function index()
{
$viewData = [
'alpha' => 'alpha text',
'beta' => 'beta text',
];
return view("my-view-file.php", $viewData);
}
}
my-view-file.php
<?php echo $alpha ?>
<br>
<?php echo $beta ?>
In the browser we get:
alpha text
beta text
Can we have html components? Yep.
We have a “main” template. And in it we set the template variables.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><?= $this->renderSection("title"); ?></title>
</head>
<body>
<?= $this->renderSection("body"); ?>
</body>
</html>
So, here we have two template variables: "title" and "body". Since the return controller can only return one template, we need to import the “main” template and then set the data in the variables.
<!-- import main.php -->
<?=$this->extend("main")?>
<!-- setup title -->
<?=$this->section("title")?>
MY title
<?=$this->endSection()?>
<!-- setup body -->
<?=$this->section("body")?>
<?php echo $alpha ?>
<br>
<?php echo $beta ?>
<?=$this->endSection()?>
How to get public JS/CSS links?
<link rel="stylsheet" href="<?= base_url('public/css/style.css') ?>"/>