{"id":207,"date":"2022-05-12T09:36:53","date_gmt":"2022-05-12T07:36:53","guid":{"rendered":"http:\/\/www.4amics.com\/x.perez\/?p=207"},"modified":"2022-05-12T09:36:55","modified_gmt":"2022-05-12T07:36:55","slug":"codeigniter-4-modular-sas","status":"publish","type":"post","link":"https:\/\/www.4amics.com\/x.perez\/2022\/05\/codeigniter-4-modular-sas\/","title":{"rendered":"CodeIgniter 4 Modular SAS"},"content":{"rendered":"\n<p>This is a Structure Application Starter, to be used as base for any project<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is CodeIgniter Modular ?<\/h2>\n\n\n\n<p>CodeIgniter is a PHP full-stack web framework that is light, fast, flexible, and secure. More information can be found at the&nbsp;<a href=\"http:\/\/codeigniter.com\/\">official site<\/a>.<\/p>\n\n\n\n<p>The &#8220;Modular Structure&#8221; allows to separate each module from other, having each one, controllers, database, filters, libraries, languages, models, routes, validations and views.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Modules<\/th><th>Module<\/th><th>Structure<\/th><\/tr><\/thead><tbody><tr><td>Modules\/<\/td><td>Home\/<\/td><td>Config<\/td><\/tr><tr><td><\/td><td><\/td><td>Controllers<\/td><\/tr><tr><td><\/td><td><\/td><td>Language<\/td><\/tr><tr><td><\/td><td><\/td><td>Views<\/td><\/tr><tr><td><\/td><td><\/td><td><\/td><\/tr><tr><td>Modules\/<\/td><td>Users\/<\/td><td>Config<\/td><\/tr><tr><td><\/td><td><\/td><td>Controllers<\/td><\/tr><tr><td><\/td><td><\/td><td>Database<\/td><\/tr><tr><td><\/td><td><\/td><td>Filters<\/td><\/tr><tr><td><\/td><td><\/td><td>Language<\/td><\/tr><tr><td><\/td><td><\/td><td>Libraries<\/td><\/tr><tr><td><\/td><td><\/td><td>Models<\/td><\/tr><tr><td><\/td><td><\/td><td>Validation<\/td><\/tr><tr><td><\/td><td><\/td><td>Views<\/td><\/tr><tr><td><\/td><td><\/td><td><\/td><\/tr><tr><td>Modules\/<\/td><td>Utils\/<\/td><td>Config<\/td><\/tr><tr><td><\/td><td><\/td><td>Controllers<\/td><\/tr><tr><td><\/td><td><\/td><td>Language<\/td><\/tr><tr><td><\/td><td><\/td><td>Libraries<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This repository holds a composer-installable app starter, with jQuery, Bootstrap4, and Login\/Register fully working module examples It has been built from the&nbsp;<a href=\"https:\/\/github.com\/codeigniter4\/CodeIgniter4\">development repository<\/a>.<\/p>\n\n\n\n<p>More information about the plans for version 4 can be found in&nbsp;<a href=\"http:\/\/forum.codeigniter.com\/thread-62615.html\">the announcement<\/a>&nbsp;on the forums.<\/p>\n\n\n\n<p>The user guide corresponding to this version of the framework can be found&nbsp;<a href=\"https:\/\/codeigniter4.github.io\/userguide\/\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#installation--updates\"><\/a>Installation &amp; updates<\/h2>\n\n\n\n<p>Go to a browsable directory (Example: c:\\xampp\\htdocs)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">composer create-project xxperez\/codeigniter4modular<\/pre>\n\n\n\n<p>then<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd codeigniter4modular<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#updates\"><\/a>Updates<\/h2>\n\n\n\n<p>Whenever there is a new release of the framework:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">composer update<\/pre>\n\n\n\n<p>When updating, check the release notes to see if there are any changes you might need to apply to your&nbsp;<code>app<\/code>&nbsp;folder. The affected files can be copied or merged from&nbsp;<code>vendor\/codeigniter4\/framework\/app<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#setup\"><\/a>Setup<\/h2>\n\n\n\n<p>Go to Codeigniter4Modular directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd codeigniter4modular<\/pre>\n\n\n\n<p>Copy&nbsp;<code>env<\/code>&nbsp;to&nbsp;<code>.env<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">copy env .env<\/pre>\n\n\n\n<p>Edit .env, and tailor for your app, specifically the baseURL and default database settings:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">app.baseURL = 'http:\/\/localhost\/codeigniter4modular\/public'\n\ndatabase.default.hostname = localhost\ndatabase.default.database = database\ndatabase.default.username = username\ndatabase.default.password = password\ndatabase.default.DBDriver = MySQLi\ndatabase.default.port = 3306<\/pre>\n\n\n\n<p>After database configuration, run migrate to ensure the table users are created:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php spark migrate -all<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#modular-configuration\"><\/a>Modular configuration<\/h2>\n\n\n\n<p>Add this lines to your .env, and adapt as necessary. The example files have english and spanish translations:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#--------------------------------------------------------------------\n# LANGUAGE\n#--------------------------------------------------------------------\napp.defaultLocale = 'en'\napp.supportedLocales = ['en','es','fr','de']\napp.negotiateLocale = true\napp.appTimezone = 'America\/Chicago'<\/pre>\n\n\n\n<p>Now, you can test the app, browse your installed directory, click on &#8220;Login&#8221; in the main page.<\/p>\n\n\n\n<p><a href=\"http:\/\/localhost\/codeigniter4modular\">http:\/\/localhost\/codeigniter4modular<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#more-about-modular-configuration\"><\/a>More about modular configuration<\/h3>\n\n\n\n<p>All modules will reside under \/Modules, but can be allocated elsewhere. When your create a module, edit \/app\/Config\/Autoload.php and add your module to the PSR4, to be able to be found.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\tpublic $psr4 = [\n            APP_NAMESPACE =&gt; APPPATH, \/\/ For custom app namespace\n            'Config'      =&gt; APPPATH . 'Config',\n            APP_NAMESPACE.'\\Controllers' =&gt; APPPATH.'Controllers',\n            'Dashboard' =&gt; APPPATH . '..\/Modules\\Dashboard' ,\n            'Users' =&gt; APPPATH . '..\/Modules\\Users' ,\n\t];<\/pre>\n\n\n\n<p>Each filter you declare inside a module, must to be aliased in app\/Config\/Filters.php to be able to be used inside a rule.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\tpublic $aliases = [\n\t\t'csrf'     =&gt; \\CodeIgniter\\Filters\\CSRF::class,\n\t\t'toolbar'  =&gt; \\CodeIgniter\\Filters\\DebugToolbar::class,\n\t\t'honeypot' =&gt; \\CodeIgniter\\Filters\\Honeypot::class,\n\t\t'auth' =&gt; \\Users\\Filters\\AuthFilter::class,\n\t\t'noauth' =&gt; \\Users\\Filters\\NoAuthFilter::class,\n\t];<\/pre>\n\n\n\n<p>Each validation you declare inside a module, must to be set in the ruleSets variable in app\/Config\/Validation.php.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\tpublic $ruleSets = [\n\t\t\\CodeIgniter\\Validation\\Rules::class,\n\t\t\\CodeIgniter\\Validation\\FormatRules::class,\n\t\t\\CodeIgniter\\Validation\\FileRules::class,\n\t\t\\CodeIgniter\\Validation\\CreditCardRules::class,\n\t\t\\Users\\Validation\\UserRules::class,\n\t];<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#modular-libraries\"><\/a>Modular libraries<\/h3>\n\n\n\n<p>Libraries within a module are used to define functions that lightweight the controllers. If you prefer to use validations inside a module library, you will need to access requests and validation objects directly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">        $request = \\Config\\Services::request();\n        $validation = \\Config\\Services::validation();\n        $validation-&gt;setRules($rules, $errors);\n        $validation-&gt;withRequest($request)-&gt;run();\n        $validationErrors = $validation-&gt;getErrors();<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#modular-creation\"><\/a>Modular creation<\/h3>\n\n\n\n<p>To create new modules, you can use spark module:create option, from base directory. For example, to create a module named &#8216;Customers&#8217;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php spark module:create Customers<\/pre>\n\n\n\n<p>Module create options: -f ModuleDir (other than App\/Modules) -c FCLMVO (Create only con[F]ig, [C]ontroller, [L]ibrary, [M]odel, [V]iew, [O]ther dirs)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php spark module:create Customers -c FCMV<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#important-change-with-indexphp\"><\/a>Important Change with index.php<\/h2>\n\n\n\n<p><code>index.php<\/code>&nbsp;is no longer in the root of the project! It has been moved inside the&nbsp;<em>public<\/em>&nbsp;folder, for better security and separation of components.<\/p>\n\n\n\n<p>This means that you should configure your web server to &#8220;point&#8221; to your project&#8217;s&nbsp;<em>public<\/em>&nbsp;folder, and not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter&nbsp;<em>public\/&#8230;<\/em>, as the rest of your logic and the framework are exposed.<\/p>\n\n\n\n<p><strong>Please<\/strong>&nbsp;read the user guide for a better explanation of how CI4 works! The user guide updating and deployment is a bit awkward at the moment, but we are working on it!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#repository-management\"><\/a>Repository Management<\/h2>\n\n\n\n<p>We use Github issues, in our main repository, to track&nbsp;<strong>BUGS<\/strong>&nbsp;and to track approved&nbsp;<strong>DEVELOPMENT<\/strong>&nbsp;work packages. We use our&nbsp;<a href=\"http:\/\/forum.codeigniter.com\/\">forum<\/a>&nbsp;to provide SUPPORT and to discuss FEATURE REQUESTS.<\/p>\n\n\n\n<p>This repository is a &#8220;distribution&#8221; one, built by our release preparation script. Problems with it can be raised on our forum, or as issues in the main repository.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular#server-requirements\"><\/a>Server Requirements<\/h2>\n\n\n\n<p>PHP version 7.2 or higher is required, with the following extensions installed:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/php.net\/manual\/en\/intl.requirements.php\">intl<\/a><\/li><li><a href=\"http:\/\/php.net\/manual\/en\/curl.requirements.php\">libcurl<\/a>&nbsp;if you plan to use the HTTP\\CURLRequest library<\/li><\/ul>\n\n\n\n<p>Additionally, make sure that the following extensions are enabled in your PHP:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>json (enabled by default &#8211; don&#8217;t turn it off)<\/li><li><a href=\"http:\/\/php.net\/manual\/en\/mbstring.installation.php\">mbstring<\/a><\/li><li><a href=\"http:\/\/php.net\/manual\/en\/mysqlnd.install.php\">mysqlnd<\/a><\/li><li>xml (enabled by default &#8211; don&#8217;t turn it off)<\/li><\/ul>\n\n\n\n<p>More info:   <a href=\"https:\/\/github.com\/XXPerez\/Codeigniter4Modular\">https:\/\/github.com\/XXPerez\/Codeigniter4Modular<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a Structure Application Starter, to be used as base for any project What is CodeIgniter Modular ? CodeIgniter is a PHP full-stack web framework that is light, fast, flexible, and secure. More information can be found at the&nbsp;official site. The &#8220;Modular Structure&#8221; allows to separate each module from other, having each one, controllers, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-207","post","type-post","status-publish","format-standard","hentry","category-other"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts\/207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/comments?post=207"}],"version-history":[{"count":1,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":208,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/posts\/207\/revisions\/208"}],"wp:attachment":[{"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/media?parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/categories?post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.4amics.com\/x.perez\/wp-json\/wp\/v2\/tags?post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}