IMG-LOGO

Tutorial

IMG
CodeIgniter 4 : Services
31 Dec-2021

Introduction

All of the core classes within CodeIgniter are provided as “services”. This simply means that, instead of hard-coding a class name to load, the classes to call are defined within a very simple configuration file. This file acts as a type of factory to create new instances of the required class.

A quick example will probably make things clearer, so imagine that you need to pull in an instance of the Timer class. The simplest method would simply be to create a new instance of that class:

$timer = new \CodeIgniter\Debug\Timer();

And this works great. Until you decide that you want to use a different timer class in its place. Maybe this one has some advanced reporting the default timer does not provide. In order to do this, you now have to locate all of the locations in your application that you have used the timer class. Since you might have left them in place to keep a performance log of your application constantly running, this might be a time-consuming and error-prone way to handle this. That’s where services come in handy.

Instead of creating the instance ourself, we let a central class create an instance of the class for us. This class is kept very simple. It only contains a method for each class that we want to use as a service. The method typically returns a shared instance of that class, passing any dependencies it might have into it. Then, we would replace our timer creation code with code that calls this new class:

$timer = \Config\Services::timer();

When you need to change the implementation used, you can modify the services configuration file, and the change happens automatically throughout your application without you having to do anything. Now you just need to take advantage of any new functionality and you’re good to go. Very simple and error-resistant.

Note

It is recommended to only create services within controllers. Other files, like models and libraries should have the dependencies either passed into the constructor or through a setter method.

Convenience Functions

Two functions have been provided for getting a service. These functions are always available.

The first is service() which returns a new instance of the requested service. The only required parameter is the service name. This is the same as the method name within the Services file always returns a SHARED instance of the class, so calling the function multiple times should always return the same instance:

$logger = service('logger');

If the creation method requires additional parameters, they can be passed after the service name:

$renderer = service('renderer', APPPATH . 'views/');

The second function, single_service() works just like service() but returns a new instance of the class:

$logger = single_service('logger');

Defining Services

To make services work well, you have to be able to rely on each class having a constant API, or interface, to use. Almost all of CodeIgniter’s classes provide an interface that they adhere to. When you want to extend or replace core classes, you only need to ensure you meet the requirements of the interface and you know that the classes are compatible.

For example, the RouterCollection class implements the RouterCollectionInterface. When you want to create a replacement that provides a different way to create routes, you just need to create a new class that implements the RouterCollectionInterface:

class MyRouter implements \CodeIgniter\Router\RouteCollectionInterface
{
    // Implement required methods here.
}

Finally, modify /app/Config/Services.php to create a new instance of MyRouter instead of CodeIgniter\Router\RouterCollection:

public static function routes()
{
    return new \App\Router\MyRouter();
}

Allowing Parameters

In some instances, you will want the option to pass a setting to the class during instantiation. Since the services file is a very simple class, it is easy to make this work.

A good example is the renderer service. By default, we want this class to be able to find the views at APPPATH.views/. We want the developer to have the option of changing that path, though, if their needs require it. So the class accepts the $viewPath as a constructor parameter. The service method looks like this:

public static function renderer($viewPath=APPPATH.'views/')
{
    return new \CodeIgniter\View\View($viewPath);
}

This sets the default path in the constructor method, but allows for easily changing the path it uses:

$renderer = \Config\Services::renderer('/shared/views');

Shared Classes

There are occasions where you need to require that only a single instance of a service is created. This is easily handled with the getSharedInstance() method that is called from within the factory method. This handles checking if an instance has been created and saved within the class, and, if not, creates a new one. All of the factory methods provide a $getShared = true value as the last parameter. You should stick to the method also:

class Services
{
    public static function routes($getShared = false)
    {
        if (! $getShared)
        {
            return new \CodeIgniter\Router\RouteCollection();
        }

        return static::getSharedInstance('routes');
    }
}

Service Discovery

CodeIgniter can automatically discover any Config\Services.php files you may have created within any defined namespaces. This allows simple use of any module Services files. In order for custom Services files to be discovered, they must meet these requirements:

  • Its namespace must be defined in Config\Autoload.php
  • Inside the namespace, the file must be found at Config\Services.php
  • It must extend CodeIgniter\Config\BaseService

A small example should clarify this.

Imagine that you’ve created a new directory, Blog in your root directory. This will hold a blog module with controllers, models, etc, and you’d like to make some of the classes available as a service. The first step is to create a new file: Blog\Config\Services.php. The skeleton of the file should be:

<?php

namespace Blog\Config;

use CodeIgniter\Config\BaseService;

class Services extends BaseService
{
    public static function postManager()
    {
        // ...
    }
}

Now you can use this file as described above. When you want to grab the posts service from any controller, you would simply use the framework’s Config\Services class to grab your service:

$postManager = Config\Services::postManager();

News

IMG
Portable Display InnoView 15.8″
News 28 May-2022

The InnoView 15.8″ convenient screen is one of the most recent sections within the China-based manufacturer’s developing stock of reasonable, lightweight monitors. 

 

Carry-around screens can be a disappointing adornment. As well numerous factors hazard item disappointment. Execution and highlights can be lacking, and they may be consistent with as it were a few of your devices. 

 

The developing utilize of smartphones and tablets is driving a require for portable arrangements, and convenient screens like this include more screen genuine domain and slope up efficiency when on the go.

 

Usually the company’s greatest screen advertising. Three other models change in estimate and setups at 14″ and 15.6″. 

 

The biggest drawback with the 15.8″ unit is the need of a touchscreen. But its welcoming cost and the in general stellar execution make this show a can’t-pass-it-up bargain.

 

This competent convenient board costs $189.99 on Amazon and $179.99 on the manufacturer’s site. It could be a plug and play USB-C versatile screen with a show capability of Full Tall Definition (FHD) with 1920 x 1080 determination and 300 nits brightness. 

 

It produces 16:9 angle proportion with a 60Hz revive rate. This makes the gadget an awfully appropriate auxiliary screen joined to much littler gadgets with minor screens. Its show capabilities are charming on the eyes. The 15.8″ demonstrate is an ultra-slim IPS show with a 178° seeing point.

 

 

It has double speakers (make obscure) and comes with three cables that interface most gadgets. These are one Mini-HDMI to HDMI cable, one USB-C to USB-C cable, and one USB-C to USB-A cable. 

 

This unit requires AC control. An 18W divider attachment connector and USB cable to control the screen are included. It has no batteries and cannot be fueled by the joined computer or tablet, indeed when they are not running on their possess battery supply.

 

 

The screen has tall energetic run, or HDR — a modern show innovation that upgrades color introduction. Moreover built in are FreeSync and moo blue light innovation for distant better;a much better;a higher;a stronger;an improved">a higher seeing experience.

 

Monitor Build The screen contains a strong metal development with exceptionally lean bezels on the beat and two sides. The foot bezel is 1.25″. The case is 0.212″ wide, 14.37″ x 9″, and weighs 1.5 lbs.

 

 

The fully black metal case is firm and has no flex when held. Thicker casing at the base houses the additional circuitry and components that make the portable panel plug and play. The base also houses the dual hi-fi speakers.

 

There is no MicroSD slot. On the lower left edge of the base is a 3.5mm headphone jack, a wheel button to access settings, and the on/off button.

 

On the right side’s bottom edge of the base, viewed from the front, are one mini-HDMI port, one USB-C port, and a micro-USB port. One of those ports must have the power connection.

 

Using It

Other than adjusting the screen to your specific needs, no hardware and software configurations are needed. If attached to a computer, the only thing you need to do is open the computer’s display settings to select how you want the panel to respond.

 

The standard computer settings usually allow the secondary monitor to either mirror the primary display or show whatever window content you drag from the primary monitor to the external panel.

 

Pushing the panel’s wheel button opens a popup window in the lower left corner. Use the wheel to select the settings you want to adjust. These include picture brightness, color elements, and audio.

 

Compatibility Matters

This InnoView monitor works with a wide array of computers and mobile devices. Typically, Microsoft Windows and Apple computers work with the included cables. However, some Apple-specific cables or adapters may be needed.

 

Apple iPhones need an adapter. Some Android smartphones will connect, but not all Android manufacturers provide a signal through the USB-C or USB-A port to drive the monitor. That could be an issue with some Android tablets as well.

 

The monitor also connects to Xbox, PS3 /PS4 /PS5, Switches, etc via the USB-C or mini-HDMI ports.

 

Linux Too, Mostly

Product information does not list this monitor’s compatibility with Linux. However, I found that in most cases the portable panel was fully functional with Linux devices.

 

Interfering factors are the hardware standards in the computer and the absence of supporting code in the particular Linux kernel driving the distribution you use.

 

For instance, when I attached the portable panel to a laptop running the KDE Neon distribution, it recognized the external monitor but would only display the screen when the settings configured it as enabled. But that automatically disabled the laptop’s screen.

 

Once connected, the portable panel had a distorted display. The Chrome OS device also threw a display fit. Mouse actions became sluggish, and opened windows only partially displayed.

 

Chrome OS, the operating system bundled with the Chrome web browser to drive the Chromebook’s operation, does not have system settings related to dual monitor display functions. So, while I could drag windows from one screen to the other on some of the Chromebook models, I could not navigate the mouse pointer beyond the Chromebook’s internal display on other models.

 

This phenomenon also occurred with other portable monitors attached to my Chromebooks.

 

The portable panel maker never claimed that the InnoView portable monitor was certified to work with either the Linux OS or with Chromebooks. Perhaps now the Linux certification can be stated.

 

The completely dark metal case is firm and has no flex when held. Thicker casing at the base houses the extra circuitry and components that make the convenient board plug and play. 

 

The base moreover houses the double hi-fi speakers. There is no MicroSD opening. On the lower cleared out edge of the base could be a 3.5mm earphone jack, a wheel button to access settings, and the on/off button.

 

 On the correct side’s foot edge of the base, seen from the front, are one mini-HDMI harbour, one USB-C harbour, and a micro-USB harbour. One of those ports must have the control connection. 

 

 Using It Other than altering the screen to your particular needs, no equipment and software configurations are required. In the event that joined to a computer, the only thing you wish to do is open the computer’s show settings to choose how you need the board to respond. 

 

 The standard computer settings more often than not permit the auxiliary screen to either reflect the essential show or appear anything window substance you drag from the essential screen to the ex

IMG
Think before Buy an AC !
News

To find out what will be an appropriate size of the AC for your room, use an AC size calculator app. These apps consider all the necessary factors such as area of your room, number of users, number of windows and doors and weather history to recommend the right fit.

Watch the warranty : 

Ask the retailer about the warranty for the brand and model you’re considering buying. Also check the manufacturer’s website.

Install it properly

To get the most from your AC, install it on a cooler side of your room which does not see as much direct sunlight. Don’t put any heat-generating devices such as a TV or a lamp near the AC. Also, make sure the location is easily accessible for quick and convenient maintenance. 

Save energy and keep electricity bill low

Every time you leave the room switch off the AC. 

Use a smart and programmable thermostat. It is very energy-efficient. It allows you to programme what hours your home will be vacant and when you will be asleep. During those times, it will adjust the temperature of your home accordingly.

Use ceiling fan

Run your AC and ceiling fan together as the latter uses less electricity and helps your AC unit function more efficiently. Ceiling fans circulate cool air all throughout the room, and that means your AC doesn’t have to work as hard to pump cool air into the room.

Regular maintenance of filter

To maintain your AC’s cooling efficiency and overall performance, routinely replace or clean filters. Clogged, dirty filters block normal airflow and reduce an AC’s efficiency significantly.

Clean the dirty air filter with a soft brush under running water. You may also rinse the dirty filter with normal detergent to remove dirt of high quantity. After washing it, make sure the filter is dried under a shaded area. Clean the air filter once every two weeks to maintain the cooling performance.

Clean condenser

Condenser is the heart of an AC. Always keep it clean to avoid dust and debris clogging up the air vents. You can just use a soft-bristled brush to clean it gently or blower to blow the dust and debris off.

Leakage proof ventilation

Leakages in our home ventilation should be checked regularly. If the ventilation system is sealed properly, AC can cool the rooms easily by consuming less electricity.

Hiring a professional

When your AC needs more than regular maintenance, hire a professional technician.

Preparing for off season

During the winter, either cover your AC or remove and store it. It will protect the unit from dust and debris. 

*** Before working on an AC, always completely turn off the power to the unit.

IMG
15.8″ Portable Display
News

The InnoView 15.8″ portable monitor is one of the latest entries in the China-based manufacturer’s growing inventory of affordable, lightweight monitors.

Carry-around monitors can be a frustrating accessory. Too many variables risk product dissatisfaction. Performance and features can be lacking, and they might be compatible with only some of your devices.

The growing use of smartphones and tablets is driving a need for mobile solutions, and portable monitors like this add more screen real estate and ramp up productivity when on the go.

This is the company’s biggest screen offering. Three other models vary in size and configurations at 14″ and 15.6″.

The biggest drawback with the 15.8″ unit is the lack of a touchscreen. But its inviting price and the overall stellar performance make this model a can’t-pass-it-up deal.

Checks Most Boxes

This capable portable panel costs $189.99 on Amazon and $179.99 on the manufacturer’s website. It is a plug and play USB-C portable monitor with a display capability of Full High Definition (FHD) with 1920 x 1080 resolution and 300 nits brightness. It produces 16:9 aspect ratio with a 60Hz refresh rate.

This makes the device a very suitable secondary monitor attached to much smaller devices with tiny screens. Its display capabilities are pleasant on the eyes.

The 15.8″ model is an ultra-slim IPS display with a 178° viewing angle.

 

 

 

It has dual speakers (make unknown) and comes with three cables that connect most devices. These are one Mini-HDMI to HDMI cable, one USB-C to USB-C cable, and one USB-C to USB-A cable.

This unit requires AC power. An 18W wall socket adapter and USB cable to power the monitor are included. It has no batteries and cannot be powered by the attached computer or tablet, even when they are not running on their own battery supply.

The monitor has high dynamic range, or HDR — a new display technology that enhances color presentation. Also built in are FreeSync and low blue light technology for a better viewing experience.

Monitor Build

The monitor has a sturdy metal construction with very thin bezels on the top and two sides. The bottom bezel is 1.25″. The case is 0.212″ wide, 14.37″ x 9″, and weighs 1.5 lbs.

The fully black metal case is firm and has no flex when held. Thicker casing at the base houses the additional circuitry and components that make the portable panel plug and play. The base also houses the dual hi-fi speakers.

There is no MicroSD slot. On the lower left edge of the base is a 3.5mm headphone jack, a wheel button to access settings, and the on/off button.

On the right side’s bottom edge of the base, viewed from the front, are one mini-HDMI port, one USB-C port, and a micro-USB port. One of those ports must have the power connection.

Using It

Other than adjusting the screen to your specific needs, no hardware and software configurations are needed. If attached to a computer, the only thing you need to do is open the computer’s display settings to select how you want the panel to respond.

The standard computer settings usually allow the secondary monitor to either mirror the primary display or show whatever window content you drag from the primary monitor to the external panel.

Pushing the panel’s wheel button opens a popup window in the lower left corner. Use the wheel to select the settings you want to adjust. These include picture brightness, color elements, and audio.

Compatibility Matters

This InnoView monitor works with a wide array of computers and mobile devices. Typically, Microsoft Windows and Apple computers work with the included cables. However, some Apple-specific cables or adapters may be needed.

Apple iPhones need an adapter. Some Android smartphones will connect, but not all Android manufacturers provide a signal through the USB-C or USB-A port to drive the monitor. That could be an issue with some Android tablets as well.

The monitor also connects to Xbox, PS3 /PS4 /PS5, Switches, etc via the USB-C or mini-HDMI ports.

Linux Too, Mostly

Product information does not list this monitor’s compatibility with Linux. However, I found that in most cases the portable panel was fully functional with Linux devices.

Interfering factors are the hardware standards in the computer and the absence of supporting code in the particular Linux kernel driving the distribution you use.

For instance, when I attached the portable panel to a laptop running the KDE Neon distribution, it recognized the external monitor but would only display the screen when the settings configured it as enabled. But that automatically disabled the laptop’s screen.

Once connected, the portable panel had a distorted display. The Chrome OS device also threw a display fit. Mouse actions became sluggish, and opened windows only partially displayed.

Chrome OS, the operating system bundled with the Chrome web browser to drive the Chromebook’s operation, does not have system settings related to dual monitor display functions. So, while I could drag windows from one screen to the other on some of the Chromebook models, I could not navigate the mouse pointer beyond the Chromebook’s internal display on other models.

This phenomenon also occurred with other portable monitors attached to my Chromebooks.

The portable panel maker never claimed that the InnoView portable monitor was certified to work with either the Linux OS or with Chromebooks. Perhaps now the Linux certification can be stated.

 

Collected from : Jack M. Germain  at technewsworld

Course

IMG
CCNA2 Chapter 3 : Network Protocols and Communications
Course - 05 Jun-2022

Chapter 3 : Network Protocols and Communications

3.1  Rules of Communication

3.2  Network Protocols and Standards

3.3  Moving Data in the Network

3.4  Summary

 

 

Click Here to Download Full PPT : Download

 

Thank you
Chapter 4 will be soon

Projects