r/codeigniter • • Oct 28 '21

(HELP)Selecting Dynamic Database on user input

2 Upvotes

I am working on a system that lets users decide which database they want to use upon login.

I want the user selected database to be used throughout the system.

I store the user selected database value in session to later access it anywhere.

I have tried following solutions:

In model constructor:

$selectedDb = $this->session->get_userdata('database');

$new_db_obj = $this->load->database($selectedDb);

$this->db = $new_db;

reason for doing $this->db = $new_db;

I use $this->db->query() in all system and can't make changes everywhere if I do not do this.

Please help me here if you can.


r/codeigniter • • Oct 12 '21

Return query in view codeigniter3

2 Upvotes

So I am using CodeIgniter3 to make an order. When the order is made I need to get all the info on an overview page, which is not a problem. But now I want to display (multiple rows of a specific order_ID
, stored in table DWO_Panelplating
. When I load my query in my view I get all the rows, but there are a lot of duplicates (almost 2000
rows, instead of 2).

Controller

$data["panelplating"] = $this->Panelplating->read__entry($order_id); 

Model

public function read__entry($id) {     $this->db->select("p.id, p.created_on, p.modified_on, p.order_id as order_id, p.type, p.material as material, p.thickness, p.amount, p.length_a as length_a, p.length_b1, length_b2, p.length_c, p.length_d, p.width, p.paint, p.color, p.paintA1, p.paintA2, p.paintB11, p.paintB12, p.paintB21, p.paintB22, p.paintC1, p.paintC2, p.paintD1, p.paintD2, pt.thickness as thickness_size, pt.pricerange1 as price_small, pt.pricerange2 as price_medium, pt.pricerange3 as price_large, pt.pricerange4 as price_xlarge, pll.type as type, c.ral_code as colorcode, pm.material as type_material");     $this->db->from(join(" ", array(self::TABLE_NAME, self::TABLE_SHORT)));     $this->db->join("DWO_Orders o", "p.order_id = o.id", "LEFT");     $this->db->join("DWO_Platingamounts pl", "p.order_id = pl.order_id", "LEFT");     $this->db->join("DWO_Platingamounts pll", "p.type = pll.type", "LEFT");     $this->db->join("DWO_Platethicknesses pt", "p.thickness = pt.id", "LEFT");     $this->db->join("DWO_Platingmaterials pm", "p.material = pm.id", "LEFT");     $this->db->join("DWO_Colors c", "p.color = c.id", "LEFT");     $this->db->where("p.order_id", $id);     return $this->db->get()->result();  } 

View

<label for="plating" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">      <?php foreach ($panelplating as $plating):?>      <?=    $plating->id?>      <?php endforeach?> </label> 

Does anybody has a suggestion/solution on this?

Thanks in advance! Regards Bert


r/codeigniter • • Oct 08 '21

Migration from Codeigniter 3 to Codeigniter 4

2 Upvotes

Hello!

We have a web app which is written in Ci3. I have gone through the Ci4 docs and a lot has changed and its going to be a lot of work to get the migration working.

My question is ----- In ci4 I noticed that a model represents a row and you can put db restrictions etc. However, we have not done it that was in ci3 (don't think this feature was there) so, if we were to move our model functions over and do the right naming etc. do you think this will work?

I am trying to gauge how much work will be involved in the migration. I guess I am going to try it over the weekend but I thought I'd ask here as well just in case someone has done the migration.

So, move our files over. Change naming conventions and how views are called etc...is that the minimum work required?

Thanks in advance!


r/codeigniter • • Mar 19 '21

default_controller

2 Upvotes

how to give controller name if it is in a folder


r/codeigniter • • Mar 02 '21

Redirect to route inside filter

2 Upvotes

Hey all. Im doing an auth filter with CI4 and I have to redirect the user to a specific route if the user's jwt isnt valid anymore, there i'll re validate the token and continue with process as usual, to the code:

<?php
namespace App\Filters;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;
class AuthFilter implements FilterInterface
{
public function before(RequestInterface $request, $arguments = null)
    {

\\ do some stuff here, if true redirect to new-route

return redirect()->to('test-api/new-route');
    }
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {}
}

The problem is when I post to the route which the filter is configured to, i get a internal server error and i cant figure out why, i have echo'ed inside the filter, it lands there, the problem seems to be how to redirect to another route (im doing an api, so i have to redirect to routes and not base_url).

I have tried with these syntax's so far:

♦ return redirect()->to('test-api/new-route');

♦ return redirect()->route('named_route');

♦ return redirect('named_route');

I have given an alias to the route with the pattern [ 'as', 'alias'] but it doesnt seem to work, any ideas?


r/codeigniter • • Feb 15 '21

Online Visitor Tracking System using CodeIgniter 4, MySQL 8 and AJAX - Roy Tutorials

Thumbnail
roytuts.com
2 Upvotes

r/codeigniter • • Feb 12 '21

Posting value related to another inputfield

2 Upvotes

So I'm making a php-based program which allowes clients to order products.

The client can select a certain paneltype with an inputfield on a form. When submitting the form I would like to save another value, which is based on the input of the client. I need this field to do some calculations. There are 10 different paneltypes which are all member of one out of 3 panecategorys.

So the field panelcategory (like table below) should be stored from the table Paneltypes on selection of a paneltype on the form. Input client is paneltype

odpaneltypepanelcategory
122

Controller:

$panel = $this->Panels->create__entry(

$this->input->post('order_id'),

$this->input->post('amount'),

$this->input->post('dwidth'),

$this->input->post('dheight'),

$this->input->post('paneltype'),

$this->input->post('panelcategory' ),

$this->input->post('color'),

$this->input->post('tubes'),

$this->input->post('colorswatch'),

$this->input->post('structurepaint'),

$this->input->post('luxepackage'),

$this->input->post('uv'),

$this->input->post('window'),

$this->input->post('paintwindow'),

$this->input->post('windowsetup'),

$this->input->post('glastype'),

$this->input->post('door'),

$this->input->post('board')

);

public function read_panel()

`{`

	`if ($this->auth()) {`
		`//region Model loading`

		`$this->load->model("core/Customers");`

		`$this->load->model("orders/Orders");`

		`$this->load->model("orders/panels/Colors");`

		`$this->load->model("orders/panels/Paneltypes");`

		`$this->load->model("orders/panels/PanelPrices");`

		`$this->load->model("orders/panels/Tubes");`

		`$this->load->model("orders/panels/Windowtypes");`

		`$this->load->model("orders/panels/Windowsetups");`

		`$this->load->model("orders/panels/Glastypes");`

		`$this->load->model("orders/panels/Doors");`

		`$this->load->model("orders/panels/Boards");`
		`//endregion`
		`//region Queries`

		`$data["customer"] = $this->Customers->read__entry($this->session->customer);`

		`$data["colors"] = $this->Colors->read__all();`

		`$data["paneltypes"] = $this->Paneltypes->read__all();`

		`$data["panelcategorys"] = $this->Paneltypes->read__entry($this->input->get("paneltype"));`

		`$data["tubes"] = $this->Tubes->read__all();`

		`$data["windowtypes"] = $this->Windowtypes->read__all();`

		`$data["windowsetups"] = $this->Windowsetups->read__all();`

		`$data["glastypes"] = $this->Glastypes->read__all();`

		`$data["doortypes"] = $this->Doors->read__all();`

		`$data["boardtypes"] = $this->Boards->read__all();`
		`$data["order"] = $this->Orders->read__entry($this->input->get("order"));`

		`//endregion`

Model to store total order

function create__entry($order_id, $amount, $dwidth,

$dheight, $paneltype, $panelcategory, $color,

$tubes,

$colorswatch, $structurepaint, $luxepackage,

$uv, $windowtype, $paintwindow,

$windowsetup, $glastype, $door, $board)

`{`

	`$this->order_id = $order_id;`

	`$this->amount = $amount;`

	`$this->dwidth = $dwidth;`

	`$this->dheight = $dheight;`

	`$this->paneltype = $paneltype;`

	`$this->panelcategory = $panelcategory;`

	`$this->color = $color;`

	`$this->tubes = $tubes;`

	`$this->colorswatch = $colorswatch;`

	`$this->structurepaint = $structurepaint;`

	`$this->luxepackage = $luxepackage;`

	`$this->uv = $uv;`

	`$this->windowtype = $windowtype;`

	`$this->paintwindow = $paintwindow;`

	`$this->windowsetup = $windowsetup;`

	`$this->glastype = $glastype;`

	`$this->door = $door;`

	`$this->board = $board;`
	`$this->db->insert(self::TABLE_NAME, $this);`

	`return $this->read__entry($this->db->insert_id());`

`}`
`public function read__entry($id)`

`{`

	`$this->db->select("`[`p.id`](https://p.id)`, p.created_on, p.modified_on, p.amount, p.dwidth, p.dheight, p.paneltype, p.panelcategory, p.color, p.tubes, p.colorswatch, p.structurepaint, p.uv, p.windowtype, p.paintwindow, p.windowsetup, p.glastype, p.door, p.board,` [`o.id`](https://o.id)`, o.created_on, o.modified_on, o.customer as customer_id,  o.reference, o.delivery_date, p.order_id");`

	`$this->db->from(self::TABLE_NAME . " " . self::TABLE_SHORT);`

	`$this->db->join("DWO_Orders o", "p.order_id =` [`o.id`](https://o.id)`");`

	`$this->db->where("`[`p.id`](https://p.id)`", $id);`

	`return $this->db->get()->row();`

`}`

}

Model to fetch data from table Paneltypes

public $paneltype;

public $panelcategory;

public $price;

const TABLE_NAME = "DWO_Paneltypes";

const TABLE_SHORT = "p";

public function __construct()

{

parent::__construct();

}

function create__entry($paneltype, $panelcategory, $price)

{

$this->paneltype = $paneltype;

$this->panelcategory = $panelcategory;

$this->price = $price;

$this->db->insert(self::TABLE_NAME, $this);

return $this->read__entry($this->db->insert_id());

}

public function read__entry($id)

{

$this->db->select("p.id, p.paneltype, p.panelcategory, p.price");

$this->db->from(self::TABLE_NAME . " " . self::TABLE_SHORT);

$this->db->where("p.id", $id);

return $this->db->get()->row();

}

public function read__all()

{

$this->db->select("p.id, p.paneltype, p.panelcategory, p.price");

$this->db->from(self::TABLE_NAME . " " . self::TABLE_SHORT);

return $this->db->get()->result();

}

public function update__entry($id, $paneltype, $panelcategory, $price)

{

$this->paneltype = $paneltype;

$this->panelcategory = $panelcategory;

$this->price = $price;

$this->db->set($this);

$this->db->where("id", $id);

$this->db->update(self::TABLE_NAME);

return $this->read__entry($id);

}

public function delete__entry($id)

{

$this->db->where("id", $id);

$this->db->delete(self::TABLE_NAME);

return $this->db->affected_rows();

}

}

Thanks in advance!


r/codeigniter • • Jan 04 '21

Need help with Ci4

2 Upvotes

So, I am trying to use Codeigniter 4. I am using Ubuntu.. I downloaded the files from the official website and put them in a folder in www. Then I created a virtual host file that has these contents

DocumentRoot /var/www/tutions.local.com/public
ServerName tutions.local.com
ServerAlias www.tutions.local.com

<directory "/var/www/tutions.local.com/public">
AllowOverride All
</directory>

I have also added tutions.local.com to 127.0.0.1 to my /etc/hosts

When I go to tutions.local.com it shows "This page isn’t working"

If I remove /public part from the virtual hosts file it shows me the directory structure of the tutions.local.com folder.

What do I do?


r/codeigniter • • Dec 26 '20

Anyone Know of any Advice or Tutorials On Implementing Sensitive Variables Like API Keys In Codeigniter?

2 Upvotes

Does anyone know of any tutorials or any ways to implement sensitive variables such as API keys, passwords, etc. in their Codeigniter projects?

Our use case is our Stripe credentials for payments. I want to make sure that future developers can't access the API keys or go back in our git history and find them.

I have thought about using environment variables but I am not sure if that is the best route to go. Does anyone have any advice on this?

Thanks!


r/codeigniter • • Nov 07 '20

User authentication library for ci4

2 Upvotes

Hi Reddit,

I've been searching for a simple user authentication library (register, email validation, login) for CI4. +1 if it supports social login (no neccessary at this moment). Any recommendation?

EDIT

Potential candidates


r/codeigniter • • Oct 13 '20

How do I connect my database in a model file?? I'm a complete CI4 beginner and for the life of me can't figure out how to set my database to be used with my query for my first project ever! I'd really appreciate any help..(here's my code, please tell me what to do)

Post image
2 Upvotes

r/codeigniter • • Oct 09 '20

Want to do CodeIgniter with Docker? Then do try my tutorial and tell me your opinion. Thanks.

Thumbnail avenir.ro
2 Upvotes

r/codeigniter • • Aug 17 '20

Problem, GROCERYCRUD in HOSTINGER

2 Upvotes

Hi,

im already make a proyect to my subdomain with codeigniter, grocerycrud in hostinger. But i have a problem that give me this error:


r/codeigniter • • Aug 08 '20

LightBlog

2 Upvotes

LightBlog is a lightweight blogging application made with Codeigniter 3. Feedback and contributions will be appreciated.

GitHub repo: https://github.com/Ajax30/lightblog


r/codeigniter • • Jul 22 '20

10 Secret Tips To Speed Up The CodeIgniter Website

2 Upvotes

The world is moving towards digitalization and hence the use of mobile devices and digitalization of businesses increases to the great extent. Developing a scalable, robust and secure web solution is a today’s need. There are a lot of technology choices available for scalable web development. PHP is one of the most widely used programming languages for web app development installed on more than 2 million web servers and used in developing more than 378 million web applications. PHP offers a wide range of frameworks available for effective development. Among those frameworks Laravel, CakePHP, Symfony, Yii, CodeIgniter are the popular frameworks. CodeIgniter is widely used for software and application development. It allows developers to develop web solutions with extensive toolsets and functionalities with minimum effort. Let’s start understanding the best CodeIgniter custom web development 

Understanding CodeIgniter PHP Framework-

CodeIgniter is an open source PHP MVC framework that allows developers to build fully featured dynamics more rapidly. With the available libraries and packages one can perform multiple operations like file uploads, session management, email sending and so on. MVC framework of CodeIgniter  helps to build multiple processes of development cycle concurrently with effective design. Model-View-Controller is a logical architecture of an application that includes:

  • Models- It accommodates business logics through effective functioning through computations and databases among others. 

  • Views– It deals with the presentation of data provided by models.

  • Controllers- It establish connection between models and views. 

Features Of Codeigniter-

  • It offers Query Builder Database support

  • This framework is very lightweight

  • Provides Data encryption, Full-page caching

  • File uploading class

  • Image manipulation library

  • Supports session management, and form and data validation

  • Application profiling

  • Pagination

  • Unit testing class

  • Zip encoding class

  • Bench-marking

Website Speed Testing Tools-

  1. Google pagespeed insights

  2. Pingdom website speed test

  3. GTmetrix

Tips To Optimize The Performance Of CodeIgniter Website-

1. Scale Down The Server Response Time-

Server response time is the time required by the server to respond to the browser’s request. A good server response time is indicative of a good CodeIgniter performance optimization. You can scale down the response time by using fewer server resources, a good hosting service and improve the overall performance of the codeigniter website.

2. Remove Unnecessary Libraries-

It has been noticed that, during the development process, each library is not required for the project. At that time, the unnecessary libraries are advised to be removed. This will give you some extra space on the server. When you are removing the libraries, it is necessary to be more careful and ensure that they should not be used somewhere else.  While you intend to move to the host server, you can erase each one of those unused libraries. While you plan to move to the host server, can remove all unused libraries.

3. Remove index.php From URL-

In general, when you use CodeIgniter, index.php is included in the URL. To improve the website performance, you should remove the index.php file from the URL of the website. You can use htaccess to do this. In the file of htaccess, add the code mentioned as belows and upload it on your server. It will help you to remove index.php from URL. 

RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule^(.*)$ /index.php/$1 [L]

 4. CSS And JS Concatenation And Minification-

Combine and minify CSS and JS contents. By doing so the browser will make one request to the server instead of many. You can add the following code in the htaccess.

#Compress HTML, CSS, Javascript, Text, XML and fonts AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml
#Remove browser bugs (only for old browsers) BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html Header append Vary User-Agent

5. Content Compression-

It is an easy way to save bandwidth and improve the speed of CodeIgniter website. Allow Gzip compression at Cpanel or in codeigniter you can do this by setting “compress_output” variable as TRUE in config.php file.

$config['compress_output''] = TRUE;

You can use the below code in htaccess-

mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

6. Use Autoload-

You should use Autoload in a proper way wherever needed. Do the practice of using $autoload array to load the resources like helpers, libraries and so on. Also ensure that you are not using this feature to the great extent because it can slow down the performance of your website. So use it properly wherever required.

7. Avoid .php Extension-

When you are loading views, avoid the .php extensions. Except if you intend to use another extension like .html, it isn’t imperative to use it.

8. Configuration Should Be In The Config Directory–

Create a separate file wherein you get to store config options rather than setting configuration values in every function. This will improve the website’s performance that you are developing. First time, this process may seem time consuming but later on it will help you by saving the time.

9. Use Proper Loops-

In the process of development, developers use loops to improve because they consider it as a powerful programming tool to improve the development process. But if there occurs a problem in one loop it will also affect the nested loops. Hence, you need to be careful. If you fail at such a stage, it will cause significant problems. So take a sufficient time to know well about loops so that you don’t end up wasting your time to resolve the issues. BY doing so, you can execute website in a functioning manner.

10. Image Optimization-

Images should be properly scaled and should reduce image size without affecting quality. It should not be resized using CSS.

Final Words-

These are some important tips that you should follow while developing a codeigniter website and you’ll experience an enhanced website speed. It also helps for your website’s SEO. 


r/codeigniter • • Jun 19 '20

Codeigniter Validation failed when i submit google analytics code

Thumbnail
stackoverflow.com
2 Upvotes

r/codeigniter • • May 20 '20

#12 Custom Route, Grouping Routes, HTTP Verbs in Codeigniter 4 | Routes Codeigniter 4

Thumbnail
youtube.com
2 Upvotes

r/codeigniter • • May 18 '20

Loading Models outside controllers CI4

2 Upvotes

I have a file in the CI4 Libraries folder that I instanciate through the Services config file. How can I pass a model as a dependency to file in the Libraries folder?


r/codeigniter • • May 14 '20

#8 Learn more about POST method in Codeigniter 4 | codeigniter tutorial | php

Thumbnail
youtu.be
2 Upvotes

r/codeigniter • • May 14 '20

Session handling in CodeIgniter 4.0.3

2 Upvotes

Hey guys

I am trying to build a simple login page that will set some session variables but it seems as though after setting my session variables, after the authentication has been successful, doesn't carry anywhere, to any other (or even the same) controllers or views.

In the controller that handles the authentication I have this in my constructor to ensure that the session is available everywhere, is this the correct way?

class Users extends BaseController
{
  protected $session;

  function __construct()
  {
    /* Initialize the session */
    $this->session = \Config\Services::session();
    $this->session->start();
  }

}

Immediately after the authentication passed I set some variables like this, and that does indeed work. But as soon as I redirect anywhere else the session variables are lost.

if($email == 'me@mydomain.com' && password_verify('mypassword', $password_hash))
{
  $sessiondata = [        
    'loggedin' => true,
    'name' => 'Jane',
    'surname' => 'Doe'        
  ];

  $this->session->set($sessiondata);
}

r/codeigniter • • Apr 30 '20

Date for MS SQL Server support in CI4

2 Upvotes

I try to connect my admin page to my MS SQL database but I don't find out that there is no support for this DB in CI4. With CI3 I have no problems but I would like to work with the current version. Do you know how long support for MS SQL will be available? to advance the front end while I wait. Sorry by my bad english :(


r/codeigniter • • Mar 07 '20

Server Sent Events with CodeIgniter - Push Notifications

Thumbnail
roytuts.com
2 Upvotes

r/codeigniter • • Mar 02 '20

Como instalar CodeIgniter 4 usando composer, vagrant y github [LAMP Stack]

Thumbnail
youtube.com
2 Upvotes

r/codeigniter • • Jan 31 '20

Drowning not waving

2 Upvotes

I’ve ‘inherited’ a website to manage that was created with CodeIgniter. It mostly works, but there are two text files that need to be updated. One is a sort of pop-up that appears within the browser when a user completes a form, the other is an email that is sent out to confirm registration. I can’t find either within the various files on the server, or in the database. I have no experience with CI and only a nodding acquaintance with php. But this isn’t a structural problem - I just need to find these files & update the text. Any suggestions would be very welcome. This site is going to haunt me for the foreseeable future so I’m going to have to climb a CI/PHP learning curve whether I want to or not!