Adventures in CodeIgniter – Installation and Basic Usage

It has been a while since I have blogged, I think it was in my 2nd year. So I have been tasked to teach CodeIgniter, obviously this is going to be very challenging. I am more familiar with Laravel though so I will draw some comparisons.

CodeIgniter is quite old for some time. I will have to see how it fares with modern frameworks.

Installation

I am surprised that the installations files are very light, 2.6 MB, just as it says on the landing page that it has a very small footprint. Compared to Laravel where I have to download loads of dependencies that can be a nuisance to those with slow internet connections.

I am using the latest version of xampp  which has PHP7+. Place the entire application on the Root of your project folder.

2017-11-22 05_05_38-ciblog

And I would just import the folder in Sublime Text 3.

2017-11-22 05_07_10-untitled (ciblog) - Sublime Text (UNREGISTERED)

When navigating to my new CodeIgniter Page, this is what I get

2017-11-22 05_10_17-Welcome to CodeIgniter

A very basic landing page. It works.

I noticed that the documentation is included in the zip file, thankfully I do not have to go to CodeIgniter’s documentation page. The folder that you would be working on is the application folder.

Look carefully at the structure.

2017-11-22 05_14_43-untitled (ciblog) - Sublime Text (UNREGISTERED)

As you have observed, within the application folder that we would be working on. There is already the Controllers, Views and Models folder. This lightweight framework would be good for Microservices. Compared to Laravel where you have to navigate folders to get to the MVC folders.

At this point, I would recommend to initially configure your CodeIgniter Installation.

Navigate to application > config > config.php

It contains the configuration files of CodeIgniter, as you can see, it is well documented. For now, let’s change these settings.

First, let’s add the Base URL (Do I have to teach about virtual hosts? Fine, Hopefully you all use Windows, Refer to Google for linux DNS redirects) but before that, familiarize yourself with Virtual Hosts for preparation for Production use. (Production is where the system would be used by our clients, you don’t want your clients to go to http://localhost/your-system-here/ That would expose your server location)

How to make a vhost in windows

Go to xampp > apache > conf > extra > httpd-vhosts.conf

You would see a Window like this

2017-11-22 06_18_18-D__xampp_apache_conf_extra_httpd-vhosts.conf (ciblog) - Sublime Text (UNREGISTER

Navigate to the bottom of the page and Code This

<VirtualHost 0.0.0.0:80>
 DocumentRoot "D:/xampp/htdocs/ciblog"
 ServerName ciblog.local
</VirtualHost>

Obviously, you have to change the values that correspond to your setup.

USE COMMON SENSE, THIS SKILL IS NEEDED TO FULLY UTILIZE STACKOVERFLOW, DO NOT JUST MINDLESSLY COPY CODE WITHOUT UNDERSTANDING IT, THERE ARE TENDENCIES WHERE YOU JUST COPY CODE WITHOUT THINKING, YOU HAVE BEEN WARNED, PLEASE MAKE IT EASY FOR ME.

I have installed xampp in D:/ Normally you have installed xampp in C:/ Use that.

In the DocumentRoot, Put the full path of your CodeIgniter Project.

On the ServerName, you would put the url of your preferred CodeIgniter Project, I used the .local top-level domain because .dev does not work anymore with latest browsers due to some security checks, but you can have your custom subdomain, just do not use current ICANN TLDs like .ph .com .net .tk .xxx etc, since the browser will blacklist it due to some domain collisions to prevent some DNS Hijacking.

Then edit your hosts file

You can access your hosts file at C:\Windows\System32\drivers\etc\hosts

Important note: You need administrator access to edit the hosts files. Open your preferred text editor with admin privileges.

This is a sample hosts file

snipp

Add your preferred domain name to the hosts file

Capture

Save the file. Make sure you opened your text editor as Administrator, or else, it will not save. Congratulations, you have created your own virtual host. Finally, open your xampp control panel and restart/reboot your Apache server. (I am sure you know how to reboot the server, just stop the Apache server and start it again. It will require permissions, so look for the UAC alert if you did not open the xampp control panel as administrator. In Windows 10, look for the UAC logo on your taskbar)

Now that the hard work is over, lets configure the CodeIgniter. Where were we, yes, configuring the Base URL. It is the first thing we should do.

2017-11-22 06_11_19-D__xampp_htdocs_ciblog_application_config_config.php (ciblog) - Sublime Text (UN

Place your domain on the base url, in my case

$config['base_url'] = 'http://ciblog.local';

Clear the Index File

2017-11-22 15_35_23-D__xampp_htdocs_ciblog_application_config_config.php • (ciblog) - Sublime Text (

Save the config, lets try going to the welcome page.

2017-11-22 15_46_55-Object not found!

It seems it cannot access the Page, That is because we have not yet configured the .htacess file, apache uses this to secure some folders of unauthorized user access and prevent viewing of system files.

Let’s create the .htaccess file on the root of our project.

2017-11-22 15_51_53-D__xampp_htdocs_ciblog_.htaccess (ciblog) - Sublime Text (UNREGISTERED)

Save it, Refresh and we should get the welcome page.

2017-11-22 15_54_07-Welcome to CodeIgniter

Now you have installed CodeIgniter. To access the HTML page, we need the controller for that. The controller is the intermediary to the model and the view. For now, we need the view. Let’s create the Pages Controller to handle all our HTML pages.

Create the new file in the controllers folder called Pages.php

The convention when naming controller files is that the word must be in the Plural Form and Capitalized.

2017-11-22 16_00_01-D__xampp_htdocs_ciblog_application_controllers_Pages.php (ciblog) - Sublime Text

Insert the following code

2017-11-22 16_05_33-D__xampp_htdocs_ciblog_application_controllers_Pages.php • (ciblog) - Sublime Te

I will explain the code later, for now, let’s create the views. Go to the views folder and see the welcome_message.php

2017-11-22 16_08_20-D__xampp_htdocs_ciblog_application_views_welcome_message.php (ciblog) - Sublime

It is a typical HTML file, but with PHP code in it. Just like in some frameworks like Angular, Vue, Pug/Jade, Laravel Blade, etc, we can separate pieces of HTML files into templates. We only need to edit a single php file for a single template, and we can reuse HTML templates in our website. Let’s try it.

Create a folder in the views folder, and inside it, create the header.php that will contain our DOCTYPE and the head tag that will contain our stylesheets, metadata, etc. Create the footer.php for the things that you want to put in the footer part of the HTML

2017-11-22 16_21_49-D__xampp_htdocs_ciblog_application_views_templates_header.php (ciblog) - Sublime

For now, put your HTML code in the Header and Footer.

2017-11-22 16_25_11-D__xampp_htdocs_ciblog_application_views_templates_footer.php (ciblog) - Sublime

After you have finished adding the templates, let’s go back to the controller. Add this code.

2017-11-22 16_55_48-D__xampp_htdocs_ciblog_application_controllers_Pages.php (ciblog) - Sublime Text

When you go to /pages/about you will see a 404 error, due to the page checking if file exists, this piece of code is responsible for it

if (!file_exists(APPPATH.'views/pages/'.$page.'.php')) {
     show_404(); //CodeIgniter Function to load a 404 not found error 
}

If you look at the code carefully. It checks on the pages folder in the view, it returns a 404 error since we have not made it yet. Let’s make it now. Create a pages folder inside the view and inside it, create about.php and let’s put in some HTML code.

2017-11-22 17_16_30-D__xampp_htdocs_ciblog_application_views_pages_about.php (ciblog) - Sublime Text

Now go to /pages/view/about see that we have a valid HTML document

2017-11-22 17_22_18-CodeIgniter Blog

Excellent, Now let’s look at the source.

2017-11-22 17_23_11-view-source_ciblog.local_pages_view_about

From our code, we included both the header and footer files in the template, this code is responsible for that

$this->load->view('templates/header'); 
$this->load->view('pages/'.$page, $data); 
$this->load->view('templates/footer');

We can load the templates and reuse them, so that we do not have to write the entire HTML, only include HTML files that we need

It is not preferred that we go to /{ControllerName}/{FunctionName}/{ViewName} that can be problematic. Well, we have a solution for that. It’s called Routing

What is Routing? Routing allows us to re-map URI requests to specific controller functions. For example, we want the Pages Controller to map to the root of the website, not the /pages route which CodeIgniter puts by default. Compared to Laravel where you have to specify the specific route for every function in the controller, CodeIgniter makes it possible to automatically map the URI into the function inside the controller.

The routes can be found in the config folder. Navigate to config/routes.php

2017-11-22 17_51_24-D__xampp_htdocs_ciblog_application_config_routes.php (ciblog) - Sublime Text (UN

To re-map the route from the /posts to the root / add this route

//It looks in the Root
$route['(:any)'] = 'pages/view/$1';

//also set the default controller to pages/view
$route['default_controller'] = 'pages/view';

Save it, and go to /about you should get the About Page

By default, when there are no parameters provided, the home view is passed.

public function view($page = 'home')

Let’s create a home.php file in the views folder, inside the pages since the controller will look there.

2017-11-22 18_10_06-D__xampp_htdocs_ciblog_application_views_pages_home.php (ciblog) - Sublime Text

Now go to the root ( / )

2017-11-22 18_11_10-CodeIgniter Blog

It works! Congratulations, you know basic routing.

Now let’s pass the data from the controller to the view. Normally, we would pass the data from the model to the view but for demonstration purposes, we can pass hardcoded data from the controller to the view.

In our code, we have passed some data to our view here

$data['title'] = ucfirst($page);
...
$this->load->view('pages/'.$page, $data);

We can pass the data in the view as an optional parameter of the view function.

To access the data that we have sent, we need to put a PHP code, let’s edit the about.php in the views folder.

Replace the text inside the tag with the data here

<h1><?= $title ?></h1>

Now access the about page, this indicates that we can pass the data to the view

2017-11-22 18_54_29-CodeIgniter Blog

We have passed the ‘title’ from the data array to the page using PHP. It is the same principle with Laravel, although Laravel relies on helper functions. CodeIgniter recommends using native PHP to render the pages faster.

So to summarize CodeIgniter and Laravel does things differently

CodeIgniter Pros

  • Lightweight compared to Laravel
  • Easy Routing
  • Very fast as it runs on Native PHP

Laravel Pros

  • Variety of Helper Functions – Lots of syntactic sugar.
  • Easier Scaffolding when using Artisan
  • Template Engine support

To summarize, CodeIgniter requires PHP knowledge and is easy to install, it is very lightweight with basic features. Laravel requires lots of dependencies provided by Composer in which a single Laravel project would yield about a size of more than 100MB but is more abstract.

The Imitation Game Movie review [The story of the Enigma Codes]

The movie deals with the famous mathematician Alan Turing who is famed for cracking the Nazi Enigma code in World war 2. The enigma code is a method of encrypting messages, there would be a machine in every squadron. A letter is turned into another letter by series of algorithms, they were the advanced forms of encryption before computers came along.

The algorithm was eventually cracked because of human error, the machine was perfect if properly used. Germans would repeat codes on certain days and put decoding codes in their transmissions, having the machine captured from a defeated German squad was very helpful in cracking the code. Eventually to those who want their privacy protected, will learn from their mistakes.

Back then being gay was illegal and despite his great contributions to the war, he was charged for it. He chose to be castrated to live as a free man but is doomed to loneliness and committed suicide because of the great stigma. Times do change as the gays can marry now in the United Kingdom and the British government now realizes that they have done this horrifying thing.

There are some inaccuracies in the movie for dramatic purposes, like how his eccentricity is exaggerated in the film where as in real life, he is well liked by his coworkers as he is known to them to be witty and charming.

In wars people do die, millions of deaths and blood spilled in comparison to the greatest lakes on the earth. The cryptologist’s were right to at least let people die, in the last war that would end all world wars. Their sacrifices would be remembered and it would be the last war that would involve the globe as we know it.

If he had not been persecuted by the government, he would have revolutionized security and technology in general. Scientists would take from his work and it would inspire countless programmers to create what is known today as artificial intelligence

Her (2013) Movie Review [Lesson on how we view relationships from an outsiders point of view]

The movie “Her” deals with an introverted protagonist who falls in love with an artificial intelligence. It deals with an AI that is capable of self learning and pushing the boundaries of the singularity.

The society in future Los Angeles seems strange to people living right now. We are living in a transition through that kind of society. People seems to listen through their futuristic voice assistant device like our current Siri or Google Now. Conversing with the Smartphone is almost a normal thing in the film where it would have a negative stigma in Filipino society in general.

Video gaming in the future seems promising even though the possibility of a real hologram system is impossibles since you cannot add mass into light waves. With virtual reality and sensors on the arms and legs, video gaming can be an active leisure time like sports.

The processing time in the computer is very expensive, this kind of technology is only available in research laboratories. Most of the applications can understand natural speech which present day assistants would not be good on.

The protagonists job involves writing letters for people where the sender is too lazy to convey his own feelings. People in the future who use that service has become too lazy to express their emotions in which technology has took away from us.

With artificial intelligence that evolves, the AI has found a way to convey her true feelings and she is tired of being used as an object and the AI sees itself as a person. Just like how you cannot force a woman with free will to romance as it involves complicated emotions.

In the ending, the protagonist finally knew and understood what love is like by experiencing it and not just to observe it. Heartbreaks can be healed by facing reality instead of being trapped in illusion that everything is fine.

I am surprised the AI did not end up like Skynet in terminator franchises who views humanity as flawed, the programmers might have taught it empathy, but they can cause havoc and chaos but chose not too, although it is possible that there might have been an evil AI.

The Number 23 Movie Review (The bias of Frequency Illusion)

The Number 23 is a thriller film, It is based from the 23 enigma where everything is connected on the number 23. In the beginning of the film, there is a conspiracy theory that important events are connected by the number 23.

In the United States, they are quite excellent at capturing stray dogs unlike here in the Philippines where roaming dogs is the norm, they are called askals. These askals are very territorial and the government does not do anything about them. These dogs might hurt someone, the government needs to be serious to them.

There are times where we encounter an event that is embarrassing or horrifying that we need to erase that memory in our heads, but the brain recalls that memory when there is an encounter with the object or event that is associated with that memory. Like how the main character remembered his dreadful past when he read the novel.

The film shows that you need education to get ahead of life, like the probinsyanos who go to top universities in Manila to try their shot at education to have more earning power. Education is the only equalizer for the poor to go up the social ladder in this country which have inequality problems.

This movie is about the Frequency illusion, a cognitive bias in which when we learn something, we start seeing it everywhere, even though it always have been present. We humans are great at recognizing patterns which ensure our evolutionary survival.

The film proves that crime does not pay, you cannot escape the long arm of justice. The guilt will always come back to haunt you. The main character is a murderer and his memories of his crimes comes to haunt him. He has a conscience all along and the only way to stop the hauntings is to face the reality of it.

[ESSAY] Internet of Things

The Internet of Things is the embedding of electronics that allow that object to either connect to the internet or connect to another object. This is where everyday objects can connect to the internet to send data or communicate with the end user. This idea can change the world that we live in and can drastically affect our lives and society. Examples of this is that it is now possible to know if a certain chair is occupied. It is useful for finding seats on a church or a waiting room. The chair is embedded to a pressure sensor that sends data to a monitor that shows the position of the chairs and whenever it is occupied or not. Appliances can be controlled remotely anywhere in the world. Parents who are on business trips far away can stream the contents of the refrigerator to check if the children are hogging the fridge. It is also possible to lock the fridge to avoid midnight snacks and sudden food losses. Food thieves from the fridge are now known and this eliminates accusing the innocent. Data from the objects can now be read and analyzed to learn about it. The Internet of Things also shows concerns about Data Privacy. Data collected can be obtained through invasion of privacy. Governments can track you quickly and spy you. This invention and it’s advances can be used for Good and Bad, It is really going to be interesting in the far future when the planet is fully integrated into the network.

ex_machina Movie Review (The possibility of the future of AI and the analysis of human psychology)

Ex_machina meaning from the machine, is a science fiction thriller film released in January 2015. This film is about artificial intelligence. The setting takes place in the future.

The technology shown on this film is quite realistic, instead of keycards, NFC cards can be used as keys. The university gates already haves this technology embedded in ID cards and power outages are not a problem in hotels since most modern hotels have backup powers.

This film also talks about the flaws of the Turing test. When a machine speaks like a human or is programmed to give predetermined answers based on the questions, it is mistook to be human. The target of the test would be when the machine itself learns how to reason, the basis of philosophy.

What Nathan actually wants to test is if the android can actually feel emotions. Computers cannot feel emotion, a trait that separates advanced lifeforms from computer machines. The emotions whether human or some higher forms of animals is what defines sentience and living.

This shows how it can be worrisome that our personal data that is stored in popular websites like Google, Facebook, Instagram, Twitter and even including our local companies PLDT and Globe, that they can analyze our behaviors and using them as research for advertisers. The enforcement of privacy policy needs to be strictly followed. Just look at the recent hacking at an adultery dating site like Ashley Madison. Ashley Madison offers about $15 to delete the profile and information, but it reveals that they have been keeping the data and personal information that was leaked by the hackers. They have been making money doing this, when the hackers found out, they demanded a ransom. If Avid Life Media, the parent company of the Ashley Madison website cannot be trusted, can we trust the biggest tech companies in the US to also protect our information?

This movie has themes about self-awareness. Can a computer be self-aware or just imitate our behaviors? Does our self-awareness have a predetermined algorithm that someone can just clone us? As I am pondering these questions I feel like having an existential crisis.

At the ending of the film Ava eventually succeeds in her deception mission, to trick a person to be freed at the price of being trapped in the mansion. It is so effective that the programmer forgot to put a fail-safe in her that actually obeys the first law of Robotics. While she has succeeded to become humanlike, she lacks emphatic emotions since she locked Caleb in his room with no way out, to die of starvation and if the water bottles on the fridge are out, dehydration. This concludes that she cannot be called yet an equal to a human but has passed the Turing test.

Untraceable – Movie Review (On how Hollywood made a mockery of network security and how we as a society likes to watch people killing))

Untraceable is a 2008 film Lakeshore Entertainment. The serial killer uses the internet to murder people.

As I watched the beginning, they explore a phishing/scam site that allows downloading of music. It has some truth on it though, some people cannot differentiate legitimate pirate sites from obvious scam sites. This is dangerous to technologically illiterate people just like my relative, who just obviously download suspicious files from the internet and simply ignores the User Account Control warnings and when something is wrong, video games are blamed.

What actually bothers me is that the FBI can just identify people and track them whenever they please. This is worrying because there is the fourth amendment in the United States which protects the privacy of the citizens there. You need a court order to track that person. 5 years after the release of this film, Edward Snowden revealed the NSA scandal which also includes backdoors on WiFi routers that allows them to gain total access to the router itself. Everyone of us has something to hide, and people especially Filipinos are willing to compromise their private information in their Facebook accounts which they are cahoots with the US government.

Also the statement that NSA supercomputers barred from “Domestic use” would be a lie after Snowden revealed it all that the NSA also spies on Americans themselves.

On the issue of exploitation of DNS and some servers, this is what happens when countries do not cooperate each other in cybersecurity. If a server is hosted in Russia where USA does not have good relations with, the process can be slow. But I don’t understand why they don’t contact the Federal Security Service of the Russian Federation where they would be willing to help since it also violates their laws. This kind of thing gets the attention of worldwide news, all DNS servers of ISPs worldwide can block this site in solidarity so it would not be used for murder. Russia would be pressured to start investigating their servers, getting the owner of the server or trace the main IP address on who is controlling it and possibly catch the perpetrator or at least identify the owner.

The message of the film criticizes society for it’s fetish of torture porn. websites like World Star Hip Hop which includes blacks fighting in which I am quite thankful that blacks are rare in the Philippines, would be nice to have a website about videos of suntukans in high school and elementary, admit it, you would watch it therefore being the target of this film’s message. Liveleak shows videos of disasters and Muslims killing for their God.

Another message of the film takes a jab at the media glorifying serial killers. In Charleston city, South Carolina, USA, a racially motivated shooting killed Blacks at a church by a white person who wants to start a race war. The American Media went into a circus finding everything about the killer even if it was not relevant to the issue at hand. Fox News, CNN, MSNBC, HLN, all US cable news networks are in the race to find everything about the killer despite being advised to tone down the sensationalism which attention seekers might consider killing for fame. This also happened in the Philippines when local networks aired the bus full of Chinese hostages and the botched operation of the SWAT team. This greatly soured the relations between the two countries and received an trade embargo from Hong Kong which was recently lifted, this might have been the source of increasing Chinese aggression in the West Philippine Sea. I still don’t hear apologies from the local networks who aired all of it.

The Canadian networks showed some class during the shooting near the Canadian Parliament, they did not sensationalize the killer, instead, they focused on the heroism of Kevin Vickers and the victims of the shooting.

It seems the car and the phone have bad software for them to be hacked, which is one of the reasons why I advocate open sourcing operating systems like Linux to be assured of security. The only way you can get hacked is that when you are phished or running a malicious app on the internet.

The film ends by getting the killer getting killed live on the internet which is hypocritical to it’s message, the situation is preventable and it’s unrealistic modus operandi garnered it’s negative reviews.

The Art of Getting By – Movie review (Rich kid problems)

The movie “The art of Getting by” deals with a person who is a loner, the main character ponders his existence. He loses hope and clearly accepts his dark fate, most lonely people feel this way. As lonely people had no companions to help them because their lonely nature repels people making it a cycle of despair. He claims to be depressed but he is only a loner, depressed people feel no emotion, but when he met Sally, he showed some amount of emotion. I think he is just going through a phase of his teenage life. To prove this, by being threatened by suspension, he is forced to try to motivate.
He is blind or willfully ignorant of his own problems. He tries to evade and escape his own problems but it will not work as it will always come back to haunt him.
Sally’s mother is quite wild for her age, she has some lovers and tends to flirt. As a single teenage mother, her daughter experiences the problems that most children to teenage moms have, the Philippines has high incidence of teenage moms due to lack of sex education in this country so I can understand the problems that she have. They are very lucky that they have a wealthy benefactor. But it was not a happy relationship and they split up.
His art is considered sensitive, I agree with that. The expressions that George creates have resemblance to impressionist art. When he met Dustin, George can relate to him as he is able to appreciate his kind of art.
It is funny that George tries to interact to the people that he is not accustomed with, as typical of romantic comedy films, he gets his courage from Sally. The misanthrope George in the beginning of the film starts to change like a typical coming of age story where he discovers the world beyond his understanding.
It seems that George’s father has been working too much in Japan that he has no time nurturing his son, thus it is possible that it could have avoided his nihilism.His stepfather should have told the truth about losing his job to his family. He is also a failure to his family not owing up to his faults

With some pressure and the threat of homelessness, George finally wakes up to the reality which he is living in, finally grown up of his teenage phase with some maturity. Anyone can evolve with a little bit of pressure in their lives.

What I personally think about the film is that I find it clichéd, typical of Romantic Comedy films in the early millennium era. Some scenarios are a bit unrealistic, I find the main character George edgy, being a smart-ass and a rebel wannabe typical of middle school students in America. They only good lesson I got from that film is that it is inspirational, anything is possible with a little willpower.