Welcome Guest, Not a member yet? Register   Sign In
  What does BaseController's initController method do?
Posted by: LansoirThemtq - 7 minutes ago - No Replies

All of my controllers are extending from BaseController, which includes the initController method. I am trying to check for certain parameters in the post data and return a JSON 404 if they are not present. However, I have noticed that the return statement in the initController code is passing the execution to the actual controller method.

I am doing this because, otherwise, I would have to check for the existence of parameters such as user_id and Post_id, and whether there is a row in the users/posts table, in every controller. This would result in repetitive code, so I am refactoring to keep it DRY.

Here is an example of the code in the BaseController's initController method:


public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) {
    // some code...
    foreach ($requestData as $key => $value) {
        // some logic...
        if (!$this->$key) {
            return $this->notFoundResponse();
        }
    }
    // some more code...
}
And here is an example of the code in an actual controller:


class Flags extends BaseController
{
    public function index()
    {
        // We have arrived here if the BaseController function returns a notFoundResponse().
    }
}


  What happened when using country_dropdown helper?
Posted by: WilayaMayang - Yesterday, 04:25 AM - No Replies

I attempted to use the helper located at https://github.com/EllisLab/CodeIgniter/...untry-code to generate a dropdown list of countries. To do this, I created a file called country_helper.php and included the helper code. In my controller, I loaded the helper using $this->load->helper('country_helper'). However, when attempting to use the function country_dropdown();, an issue occurred.


  Apply where clause to updateBatch CI 4.3.3
Posted by: brex74 - Yesterday, 04:23 AM - No Replies

I'm using CI 4.3.3 and I can't apply the where filter on the table to update.
I can only filter with joins (onConstraint) ?
I can't find examples on CI 4.3.3 where you use the builder->where(...) combined with updateBatch.

I tried this way but it doesn't work, the where clause does not appear.

$builder->setData($data)
        ->onConstraint(["code" => "code"])
        ->where("company_id", 12)
       ->updateBatch();


Thanks


Lightbulb Possible typos at "The Fine Print" page (at "Welcome to CodeIgniter")
Posted by: Nikolice - Yesterday, 01:57 AM - No Replies

Greetings!
I am not sure about my message being posted at the correct place, but – maybe you will find it useful!
The page of The Fine Print (at CodeIgniter's main web-site) contains typos found by a “LanguageTool” plugin (for web-browsers). Also, I use a plugin to make what I see editable online (WYSIWYG) – as it enables the LanguageTool to start checking the loaded and displayed page.

Id est:
“we has” → “we have” (seems an error, but I'm not an English-native)
“web site” → “website” (twice)
“independent from” → “independent of” (you may be more sure about that; I'm not)
“the text around it” → “the surrounding text” (you choose)

Thanks for watching; and good luck to you.


  Implementing Google Maps autocomplete in CodeIgniter 4?
Posted by: SomeenKopatri - Yesterday, 12:15 AM - Replies (1)

How can one implement a Google Maps JavaScript API based autocomplete search box for places using CodeIgniter 4?


  How to improve Excel file upload speed?
Posted by: GrehklkYonccd - 03-28-2023, 09:01 PM - No Replies

I have a Codeigniter project where I need to upload and update an Excel file with approximately 5000 records to a database. However, this process takes about 15 minutes to complete, which is not ideal for the user who has to wait until all the update queries are finished. Can you suggest any ideas to run this task in the background, so that the user doesn't have to wait for it to complete?


  How to pull routes in spark command
Posted by: ciUser43 - 03-28-2023, 04:12 PM - Replies (3)

Previously up to version 4.2.12 I can call

PHP Code:
route_to('route_name'
and get the routes that I configured in the
PHP Code:
\app\Config\Routes.php 
, but since I upgraded to version 4.3.2 it seems that this is no longer possible due to the spark command not even including the Routes.php file.

I mainly used the command to send automated email with the link to a page in the application, and using the route_to function was a simple way to keep track of the routes.
Any suggestion on how to do this now in 4.3.2?
I don't recall in the upgrade instruction there was any information on how to do this.


Thanks.

After a quick check it seems that I can call "Services::routes()->loadRoutes();" and that loads all my custom routes in the spark command.

But not sure if that's the correct approach.


  Athentication classes
Posted by: manuel357 - 03-28-2023, 01:18 PM - Replies (1)

Hi, how are you? I will try to explain my problem in english, sorry if not good.
I am upgrading codeigniter to version 4.0 from 3.0, and I face the following problem:
On codeigniter 3 I have an authentication class:

PHP Code:
<?php

 
class Common_Auth_Controller extends CI_Controller {

 public function 
__construct() {

 
parent::__construct();

 
$is_logged_in $this->session->userdata('is_logged_in');
 if(!isset(
$is_logged_in) || $is_logged_in != true)
 {
 echo 
"<center>";
 echo 
"<b>No tienes permisos para acceder a esta seccion. <br> Haga click </b> " anchor(site_url("login"), "aqui"'target="_parent"');
 echo 
"</center>";
 die();
 }
 else if(
$this->session->userdata('id_sesion') != ""//si ya tiene un id de sesion
 
{
 
$this->load->model('sesiones_model');
 
$tipo $this->session->userdata('tipo');
 
 
//se verifica que la sesion actual sea la que esta en la base
 
 
if($tipo!=1)
 {
 if(!
$this->sesiones_model->verificarSesionAbierta($this->session->userdata('id_sesion')))
 {
 
redirect('sesion/cargar_sesion');
 }
 }
 }
 }
 }
?>

That class was in /application/core/ directory so the classes that I have in my controllers directory extends from Common_Auth_Controller to check if the user is logged or not.
But, now in codeigniter 4 I don't have the core directory, I would like to know in which directory I could create the class Common_Auth_Controller

Thanks,
Manuel


  Why does HTTP 303 error occur?
Posted by: BhrabhMikchel - 03-28-2023, 05:41 AM - Replies (1)

I am developing a RESTful API and I started with the User module. I created a route for user creation with the following code:

php

$routes->post('users', 'UsersController::create');
However, when I tried to access the endpoint using Insomnia, I kept getting redirected to the default controller with the message "HTTP 303 See Other". Interestingly, when I changed the verb to PUT and the route to "put()", everything worked smoothly.

My question is: Did I miss a step in the process?

Here are some additional details about my code:

In the Routes.php file, I have set the default namespace to 'App\Controllers', default controller to 'Home', default method to 'index', and disabled URI dashes translation. I have also overridden the 404 error page and enabled auto-routing.

My UsersController is extending the CodeIgniter\RESTful\ResourceController.


  I would like my website to be accessible from another machine
Posted by: KammalJeriya - 03-28-2023, 05:31 AM - Replies (1)

[font=Söhne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji']I am currently using CodeIgniter 4 and I would like my website to be accessible from another machine. Previously, I attempted to change the localhost IP to my machine IP, and it worked when opening the index.php page, but when I navigated to another page, it redirected to localhost:8080/anotherpage.php instead of my machine's IP. Is there a way to resolve this issue and access my website using my machine's IP without modifying the localhost IP? Please note that I do not have an .htaccess file in my project,[/font]


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
What does BaseController'...
by LansoirThemtq
7 minutes ago
What's the equivalent of ...
by MitchelBraybh
40 minutes ago
Error when try to upload ...
by kenjis
2 hours ago
Why Class 'Public_Control...
by MahishTanzon
3 hours ago
Getting an error message ...
by HanogThamers
5 hours ago
source code says Request:...
by kenjis
10 hours ago
Is there a good reason CI...
by kenjis
11 hours ago
Implementing Google Maps ...
by JustJohnQ
Yesterday, 07:28 AM
What happened when using ...
by WilayaMayang
Yesterday, 04:25 AM
Apply where clause to upd...
by brex74
Yesterday, 04:23 AM

Forum Statistics
» Members: 54,461
» Latest member: jackyhzzj
» Forum threads: 76,438
» Forum posts: 370,911

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB