\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Tính Vy (tinhvy)} \pdfinfo{ /Title (codeigniter4-for-beginners.pdf) /Creator (Cheatography) /Author (Tính Vy (tinhvy)) /Subject (CodeIgniter4 for Beginners Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{0856A3} \definecolor{LightBackground}{HTML}{EFF4F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{CodeIgniter4 for Beginners Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Tính Vy (tinhvy)} via \textcolor{DarkBackground}{\uline{cheatography.com/132374/cs/26789/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Tính Vy (tinhvy) \\ \uline{cheatography.com/tinhvy} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 4th March, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{TOPIC 1: GETTING STARTED}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{1.1. Installation}}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-angle-right\}\}Download Composer} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}{\emph{\{\{popup="https://getcomposer.org/Composer-Setup.exe"\}\}composer\{\{/popup\}\}}}} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-angle-right\}\}Using Composer} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`composer create-project codeigniter4/appstarter yourappname`} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{1.2. Prepare Running Your App}}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Configure CI4 to display error messages}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\emph{\{\{fa-angle-right\}\} Root|env}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Change `env` to `.env`} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\emph{\{\{fa-angle-right\}\} Root|.env}}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`\# ENVIRONMENT` \{\{nl\}\} `CI\_ENVIRONMENT = development`} \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Hosting with Apache}}} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{{\emph{Virtual Hosting}}}}} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Step 1: In \seqsplit{xamp|apache|conf|httpd.conf} \{\{fa-angle-down\}\}} \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`\# Virtual hosts`\{\{nl\}\} `Include \seqsplit{conf/extra/httpd-vhosts.conf`}} \tn % Row Count 12 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Step 2: \seqsplit{xamp|apache|conf|extra|httpd-vhosts}.conf \{\{fa-angle-down\}\}} \tn % Row Count 14 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}` \textless{}VirtualHost *:80\textgreater{} \{\{nl\}\} ServerName yourappname.local\{\{nl\}\} DocumentRoot "D:/xampp/htdocs/yourappname/public"\{\{nl\}\} \textless{}Directory "D:/xampp/htdocs/yourappname/public"\textgreater{}\{\{nl\}\} Options Indexes FollowSymLinks\{\{nl\}\} AllowOverride All\{\{nl\}\} Require all granted\{\{nl\}\} \textless{}/Directory\textgreater{}\{\{nl\}\} \textless{}/VirtualHost\textgreater{}\{\{nl\}\}`} \tn % Row Count 22 (+ 8) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Step 3: Edit the hosts file \{\{fa-angle-down\}\}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}The hosts file is used to map domain names to IP addresses. You can find this file at {\emph{`C:\textbackslash{}Windows\textbackslash{}System32\textbackslash{}drivers\textbackslash{}etc\textbackslash{}hosts}}` (on Windows) or /etc/hosts (on Linux or macOS). Add the following line to the hosts file:} \tn % Row Count 28 (+ 6) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`127.0.0.1 yourappname.local`} \tn % Row Count 29 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Finally\{\{fa-angle-down\}\}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{1.2. Prepare Running Your App}} (cont)}} \tn % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Restart Apache in the XAMPP control panel.} \tn % Row Count 1 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{{\emph{Remove public/index.php/ from URL}}}}} \tn % Row Count 2 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Step 1: Change the `{\emph{App.php}}` file} \tn % Row Count 3 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Open \seqsplit{`project\_name/app/Config/App}.php*` \{\{nl\}\}\{\{nl\}\} changes are as follows: \{\{nl\}\} `public \$baseURL = \seqsplit{'http://localhost:8080';`} \{\{nl\}\} to \{\{nl\}\} `public \$baseURL = \seqsplit{'http://localhost/your\_project\_name/';`}} \tn % Row Count 8 (+ 5) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}And the second change in the `{\emph{app.php}}` file: \{\{nl\}\} `{\emph{public \$uriProtocol = 'REQUEST\_URI';}}` \{\{nl\}\}to\{\{nl\}\} `{\emph{public \$uriProtocol = 'PATH\_INFO';}}`} \tn % Row Count 12 (+ 4) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Step 2: Copy `{\emph{index.php}}` and `{\emph{.htaccess}}`} \tn % Row Count 13 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Go to `{\emph{public directory}}` \{\{nl\}\} Copy `{\emph{index.php}}` and `{\emph{.htaccess}}` \{\{nl\}\} To\{\{nl\}\}codeigniter app root directory} \tn % Row Count 16 (+ 3) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Step 3: Change the `{\emph{index.php}}`} \tn % Row Count 17 (+ 1) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}In the root project directory, open `{\emph{index.php}}` and edit the following line: \{\{nl\}\} `{\emph{\$pathsPath = FCPATH . '../app/Config/Paths.php';}}` \{\{nl\}\}change TO\{\{nl\}\} `{\emph{\$pathsPath = FCPATH . 'app/Config/Paths.php';}}` \{\{nl\}\} If the above solution is not work for; so you can configure your apache server; as shown below: \{\{nl\}\} In the apache server, the {\bf{mode rewrite}} is already on. But some default values need to be changed on `{\emph{/etc/apache2/apache2.conf}}` file. Following are changes,\{\{nl\}\} First, find\{\{nl\}\}\{\{nl\}\} `{\emph{\textless{}Directory /var/www/\textgreater{}\{\{nl\}\} Options Indexes FollowSymLinks\{\{nl\}\} AllowOverride None\{\{nl\}\} Require all granted\{\{nl\}\} \textless{}/Directory\textgreater{}}}`\{\{nl\}\} And change `{\emph{AllowOverride}}` None to `{\emph{All}}` and {\bf{save}}.\{\{nl\}\} Then enable mode rewrite \{\{nl\}\} Then restart the server,\{\{nl\}\}} \tn % Row Count 34 (+ 17) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{1.3. Run the application in a browser}}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Local Development Server} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`php spark serve`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Virtual Hosting} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Ex: \{\{link="http://yourappname.localhost"\}\}yourappname.localhost\{\{/link\}\}`} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Removing the index.php} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`http://localhost/your\_project\_name/`}} \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{TOPIC 2: VIEW LAYOUTS}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{How to integrate an admin layout into CodeIgniter 4 so that it is separate from the public layout.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{2.1. Create a folder for admin layout}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{In the `{\bf{{\emph{app/Views}}}}` folder,} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Create a new folder named `{\bf{{\emph{admin}}}}` to hold the layout files for the admin page. \{\{nl\}\} For example: `{\bf{{\emph{app/Views/admin/layout.php}}}}`.} \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{2.2. Create a layout file for the admin page}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\textless{}!-{}- \newline app/Views/admin/layout.php \newline \newline In the admin folder, create a generic layout file for your admin page. \newline For example: \seqsplit{app/Views/admin/layout.php.} \newline In this file, you can define layout elements such as header, menu, footer, \newline and content. \newline \newline For example: \newline -{}-\textgreater{} \newline \textless{}!DOCTYPE html\textgreater{} \newline \textless{}html lang="en"\textgreater{} \newline \textless{}head\textgreater{} \newline \textless{}meta charset="UTF-8"\textgreater{} \newline \textless{}title\textgreater{}Admin Layout\textless{}/title\textgreater{} \newline \textless{}/head\textgreater{} \newline \textless{}body\textgreater{} \newline \textless{}header\textgreater{} \newline \textless{}h1\textgreater{}Admin Header\textless{}/h1\textgreater{} \newline \textless{}/header\textgreater{} \newline \textless{}nav\textgreater{} \newline \textless{}ul\textgreater{} \newline \textless{}li\textgreater{}\textless{}a href="\#"\textgreater{}Dashboard\textless{}/a\textgreater{}\textless{}/li\textgreater{} \newline \textless{}li\textgreater{}\textless{}a href="\#"\textgreater{}Users\textless{}/a\textgreater{}\textless{}/li\textgreater{} \newline \textless{}li\textgreater{}\textless{}a href="\#"\textgreater{}Settings\textless{}/a\textgreater{}\textless{}/li\textgreater{} \newline \textless{}/ul\textgreater{} \newline \textless{}/nav\textgreater{} \newline \textless{}main\textgreater{} \newline \textless{}?php echo \$this-\textgreater{}renderSection('content') ?\textgreater{} \newline \textless{}/main\textgreater{} \newline \textless{}footer\textgreater{} \newline \textless{}p\textgreater{}Admin Footer\textless{}/p\textgreater{} \newline \textless{}/footer\textgreater{} \newline \textless{}/body\textgreater{} \newline \textless{}/html\textgreater{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{2.3. Create view files for each admin page}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{app\textbackslash{}Views\textbackslash{}admin\textbackslash{}dashboard.php} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}` \textless{}?php \$this-\textgreater{}extend('admin/layout') ?\textgreater{} \{\{nl\}\} \{\{nl\}\} \textless{}?php \$this-\textgreater{}section('content') ?\textgreater{}\{\{nl\}\} \textless{}h2\textgreater{}Dashboard\textless{}/h2\textgreater{}\{\{nl\}\} \textless{}p\textgreater{}Welcome to the admin dashboard!\textless{}/p\textgreater{}\{\{nl\}\} \textless{}?php \$this-\textgreater{}endSection() ?\textgreater{}\{\{nl\}\} `} \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{2.4. Create routes for admin page}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{app/Config/Routes.php} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}` \$routes-\textgreater{}group('admin', \{\{nl\}\} {[}'namespace' =\textgreater{} 'App\textbackslash{}Controllers\textbackslash{}Admin'{]}, \{\{nl\}\} function(\$routes) \{\{\{nl\}\} \$routes-\textgreater{}get('dashboard', 'Dashboard::index');\{\{nl\}\} \$routes-\textgreater{}get('users', 'Users::index');\{\{nl\}\} \$routes-\textgreater{}get('settings', 'Settings::index');\{\{nl\}\} \});\{\{nl\}\} `} \tn % Row Count 8 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Here, all routes for the admin page start with the prefix admin, and all the controllers for the admin page are located in the App\textbackslash{}Controllers\textbackslash{}Admin namespace.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{2.5. Create controllers for the admin page}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{app\textbackslash{}Controllers\textbackslash{}Admin\textbackslash{}Dashboard.php} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}` \textless{}?php \{\{nl\}\} namespace App\textbackslash{}Controllers\textbackslash{}Admin;\{\{nl\}\} use CodeIgniter\textbackslash{}Controller;\{\{nl\}\} \{\{nl\}\} class Dashboard extends Controller\{\{nl\}\} \{\{\{nl\}\} public function index()\{\{nl\}\} \{\{\{nl\}\} return view('admin/dashboard');\{\{nl\}\} \}\{\{nl\}\} \}\{\{nl\}\} `} \tn % Row Count 7 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{In each of these controller files, you need to inherit from CodeIgniter\textbackslash{}Controller and define a method to display the corresponding page. In this method, you can use the view helper to display the file view corresponding to that page.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{TOPIC 1: NAMING CONVENTION}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Controller file and class}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{File: `UsersController.php`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`class UsersController extends Controller \{\}`} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{URI Segments}}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\emph{The segments in the URL, in following with the Model-View-Controller approach, usually represent:}}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{`example.com/class/method/ID`}} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-check\}\}The first segment represents the controller class that should be invoked.\{\{nl\}\} \{\{fa-check\}\}The second segment represents the class method that should be called.\{\{nl\}\} \{\{fa-check\}\}The third, and any additional segments, represent the ID and any variables that will be passed to the controller.} \tn % Row Count 11 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{Work with Subdirectory Controllers}}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{namespace}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`namespace App\textbackslash{}Controllers\textbackslash{}Foldername;`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{use}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`use App\textbackslash{}Controllers\textbackslash{}BaseController; \{\{nl\}\} Class Classname extends BaseController()`} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Config|Routes}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`\$routes-\textgreater{}get('/foldername','foldername/controllername::method');`} \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{Database Migration}} (copy)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Creating Databases in the Command Line}} \newline % Row Count 1 (+ 1) -{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-- \newline % Row Count 2 (+ 1) ~~~`php spark db:create foo`% Row Count 3 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{6. Creating a table}}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Run CLI}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`php spark migrate:create create\_nameoftable`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Open created file :}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\{\{fa-check\}\} Add code to `up()` and `down()` method} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Run CLI}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\{\{fa-check\}\} migrate: `php spark migrate`\{\{nl\}\} \{\{fa-check\}\} rollback:`php spark migrate:rollback`\{\{nl\}\} \{\{fa-check\}\} refresh:`php spark migrate:refresh`\{\{nl\}\} \{\{fa-check\}\} status:`php spark migrate:status`} \tn % Row Count 11 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\emph{Creating and Dropping Tables Document}} \newline https://codeigniter.com/user\_guide/dbmgmt/forge.html\#id4 \newline {\emph{MySQL Cheat Sheet}} \newline https://cheatography.com/davechild/cheat-sheets/mysql/ \newline {\emph{Up() method}} \newline `\$fields = {[}{]};` \newline `\$forge-\textgreater{}addField('id');` \newline `\$forge-\textgreater{}addField(\$fields);` \newline `//\$forge-\textgreater{}addPrimaryKey('id');` \newline `\$forge-\textgreater{}createTable('itscore');` \newline {\emph{down() method}} \newline `\$forge-\textgreater{}dropTable('itscore');`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{{\bf{5. Connect to the database}}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Create database \& its user:}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Open PhpMyadmin \{\{fa-angle-right\}\} Create a database \{\{fa-angle-right\}\} Create a user} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Edit file `.env`: }}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`\#-{}-{}-{}-{}-{}-{}-{}-{}-`\{\{nl\}\} `\# DATABASE`\{\{nl\}\} `\#-{}-{}-{}-{}-{}-{}-{}-{}-`\{\{nl\}\} \seqsplit{`database.default.hostname} = localhost`\{\{nl\}\} \seqsplit{`database.default.database} = databasename`\{\{nl\}\} \seqsplit{`database.default.username} = username`\{\{nl\}\} \seqsplit{`database.default.password} = password`\{\{nl\}\} \seqsplit{`database.default.DBDriver} = MySQLi`} \tn % Row Count 10 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\emph{Run app in a browser to see if you get any errors. If not, your connection is sucessful.}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Some common CLI commands}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{php spark serve \newline -\textgreater{} This command starts the development server and serves your CodeIgniter 4 application on http://localhost:8080/. \newline \newline php spark make:controller MyController \newline - \textgreater{}This command creates a new controller named MyController in the app/Controllers directory. \newline \newline php spark make:model MyModel \newline -\textgreater{} This command creates a new model named MyModel in the app/Models directory. \newline \newline php spark make:migration create\_users\_table \newline -\textgreater{} This command creates a new migration file for creating a users table in your database. \newline \newline php spark migrate \newline -\textgreater{} This command runs any pending database migrations. \newline \newline php spark db:seed MySeeder \newline -\textgreater{} This command seeds your database with data using the specified seeder class name. \newline \newline /{\emph{These are just a few examples of the many CLI commands available in CodeIgniter 4. You can run php spark to see a list of all available commands and their descriptions.}}/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}