Welcome Guest, Not a member yet? Register   Sign In
  Controller Filter Not Running
Posted by: occitan - 10 hours ago - Replies (1)

I am new to using filters so please forgive me if I am not understanding. Following the docs, I have the code below, but nothing happens when I visit that controller method (cases/index):

What am I missing? 

I am using version 4.4.4.


PHP Code:
App/Filters/AuthenticationFilter.php

[php]namespace App\Filters;
use 
CodeIgniter\Filters\FilterInterface;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Config\Services;

class 
AuthenticationFilter implements FilterInterface {
    public function before(RequestInterface $request$arguments null) {
        $this->session Services::session();
        if (!$this->session->has('loggedin') || !$this->session->loggedin == true) {
            redirect('login');
        }
    }

    public function after(RequestInterface $requestResponseInterface $response) {
      
    
}  



App/Config/Filters,php

PHP Code:
[php]namespace Config;
use 
CodeIgniter\Config\BaseConfig;
use 
CodeIgniter\Filters\CSRF;
use 
CodeIgniter\Filters\DebugToolbar;
use 
CodeIgniter\Filters\Honeypot;
use 
CodeIgniter\Filters\InvalidChars;
use 
CodeIgniter\Filters\SecureHeaders;

class 
Filters extends BaseConfig
{
    /**
    * Configures aliases for Filter classes to
    * make reading things nicer and simpler.
    *
    * @var array<string, class-string|list<class-string>> [filter_name => classname]
    *                                                    or [filter_name => [classname1, classname2, ...]]
    */
    public array $aliases = [
        'csrf'          => CSRF::class,
        'toolbar'      => DebugToolbar::class,
        'honeypot'      => Honeypot::class,
        'invalidchars'  => InvalidChars::class,
        'secureheaders' => SecureHeaders::class,
        'authentication' => \App\Filters\AuthenticationFilter::class,
    ];

    /**
    * List of filter aliases that are always
    * applied before and after every request.
    *
    * @var array<string, array<string, array<string, string>>>|array<string, list<string>>
    */
    public array $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
            // 'invalidchars',
        ],
        'after' => [
            'toolbar',
            // 'honeypot',
            // 'secureheaders',
        ],
    ];

    /**
    * List of filter aliases that works on a
    * particular HTTP method (GET, POST, etc.).
    *
    * Example:
    * 'post' => ['foo', 'bar']
    *
    * If you use this, you should disable auto-routing because auto-routing
    * permits any HTTP method to access a controller. Accessing the controller
    * with a method you don't expect could bypass the filter.
    */
    public array $methods = [];

    /**
    * List of filter aliases that should run on any
    * before or after URI patterns.
    *
    * Example:
    * 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
    */
    public array $filters = [
        'AuthenticationFilter' => ['before' => ['cases/index']]
    ];


  Entity magic __get not called in second generation child class
Posted by: rockinmusicgv - Yesterday, 11:45 AM - Replies (2)

I am working on an application where I have two very closely related types of data, sort of on par with Shape and ColoredShape.  ColoredShape implements all the features and has all the types of shape, but has new, cool features that regular old Shape wants nothing to do with.  That is a bit simplistic, but consider they might be implemented as follows:

PHP Code:
class Shape implements \CodeIgniter\Entity\Entity
{

}

class 
ColoredShape extends \App\Entities\Shape
{
  public function getColor()
  {
    // this throws a property not found exception
    // ignore how useless this is in production.
    return $this->color;
  }



Within the ColoredShape class, I have the getColor() method.  When I try to access the $this->color property, I get a property not found exception.  I did some digging and found that the ColoredShape class doesn't use the __get() method defined in the base Entity class.  I also found that if I add a __get() magic method in Shape, ColoredShape will access Shape's __get() method.  So, I'm wondering if my understanding of inheritance is wrong or incorrect.  Is it possible to use the Entity class's __get() method a few generations down?
Another interesting thing I found is that if you use parent::__get() within the ColoredShape class, an out of memory exception is generated.  Just with a quick glance, I couldn't see the reason for that to happen.  Can anyone explain what might cause that?
Finally, would a trait be useful here?  I.e., I would move all the "shape" logic into a shape trait, then implement the unique colored shape within the ColoredShape class, and inheriting directly from the base Entity class.


  Extending class Config\Autoload
Posted by: ozornick - 09-07-2024, 09:01 AM - Replies (5)

Why? I would like to automate the loading of modules through setting up a single Config\Components file. It will have paths, names, psr... for components and other parameters that need access from the entire project. He needs to edit Config\Autoload to add new dependencies.
If you put a code call in app/Common.php this won't work - the configs haven't loaded yet. 
The Registrar cannot be used.
Maybe this is implemented using Services
Example:

PHP Code:
    // Call inject() method
    // Edit PSR-4 for Autoload
    $autoloadConfig->ps4 + [
        // APP_NAMESPACE  => APPPATH,
        'Tools\\' => ROOTPATH 'tools/',
        'Ads\\' => ROOTPATH 'ads/',
    ];
    // Edit non-class files 
    $files $autoloadConfig->files + [
        ROOTPATH 'tools/Common.php',
    ];

    // isLoaded($name) method
    // getLoaded() method 


  Routing POST instead post
Posted by: pippuccio76 - 09-07-2024, 07:06 AM - Replies (2)

hi , in the new version i have the error that action metod must be uppercase instead lowercase (POST,PUT,GET,DELETE instead of post,put,get,delete) , i have a problem with ajax request :

Code:
$.ajax({

                    url: "<?php echo base_url('/AjaxRequest/get_Clienti_sedi'); ?>",
                    method: "POST",
                    data: {
                        id_clienti: id_clienti,
                    },
                    dataType: "JSON",
                    success: function(sedi) {

                        var html = '';

                        for (var num_row = 0; num_row < sedi.length; num_row++) {

                            html += '<option value="' + sedi[num_row].id + '">' + sedi[num_row].nome_sede + '</option>';

                        }

                        $('#id_id_clienti_sedi').html(html);



                    },
                    error: function() {
                        alert("Chiamata fallita, si prega di riprovare...");
                    }

                });

in my controller :

Code:
if ($this->request->getMethod() === 'POST')
but the code dont go inside if ... because if i do :
Code:
            log_message('debug','get_Clienti_sedi NO POST '.$this->request->getMethod());



i have :

get_Clienti_sedi NO POST post in my log .

Why?

ps i dont understand how use code in this way... isn't better use [CODE]
tag ?[/code]


  CodeIgniter v4.5.5 bug fix released
Posted by: kenjis - 09-07-2024, 01:57 AM - Replies (1)

We're pleased to announce the release of CodeIgniter v4.5.5.
This version includes four bug fixes including two fixes in Validation class and refactoring improvements:

All v4.5.x users should upgrade.

ChangeLog: https://codeigniter.com/user_guide/chang...4.5.5.html
Upgrading Guide: https://codeigniter.com/user_guide/insta...e_455.html


  futurism.com. Human Developers Will Soon Be a Thing of the Past
Posted by: Renta Ardhana - 09-05-2024, 08:13 AM - Replies (2)

In Leaked Audio, Amazon Cloud CEO Says Human Developers Will Soon Be a Thing of the Past
https://futurism.com/the-byte/aws-ceo-human-devs-ai

Leaked Amazon Recording: Cloud Chief Discusses AI’s Potential to Evolve Developer Work
https://www.econotimes.com/Amazon-Leaks-...ft-1684859

Leaked AWS Recording
https://www.businessinsider.com/insider-...-recording


  xml_convert error in long space and end content in javascript 4.5.4
Posted by: startup - 09-04-2024, 12:28 PM - Replies (3)

in this case, code working

PHP Code:
$rm_question  trim(preg_replace('/\s+/'' 'xml_convert($cauhoi))); 

in javascript show:
Code:
learntips: '&lt;p&gt;Chọn &lt;strong&gt;đ&amp;aacute;p &amp;aacute;n 2&lt;/strong&gt; trong mẹo nh&amp;eacute;.&lt;/p&gt;

in this case, code dont work so middle space in the content and end content
PHP Code:
$rm_question  =  xml_convert($cauhoi))); 

Code:
&lt;p&gt;Chọn &lt;strong&gt;đ&amp;aacute;p &amp;aacute;n 2&lt;/strong&gt; trong mẹo nh&amp;eacute;.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Mẹo h&amp;agrave;nh vi sai bị nghi&amp;ecirc;m cấm, kh&amp;ocirc;ng được khi tham gia giao th&amp;ocirc;ng&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cố &amp;yacute; l&amp;agrave;m hỏng&lt;/li&gt;
&lt;li&gt;Bu&amp;ocirc;ng cả hai tay&lt;/li&gt;
&lt;li&gt;Tr&amp;ecirc;n cầu hẹp một l&amp;agrave;n xe&lt;/li&gt;
&lt;li&gt;Đi v&amp;agrave;o phần đường d&amp;agrave;nh cho người đi bộ&lt;/li&gt;
&lt;li&gt;Chạy qu&amp;aacute; tốc độ tối đa cho ph&amp;eacute;p&lt;/li&gt;
&lt;li&gt;Lạng l&amp;aacute;nh đ&amp;aacute;nh v&amp;otilde;ng&lt;/li&gt;
&lt;li&gt;Vận chuyển tr&amp;aacute;i ph&amp;eacute;p h&amp;agrave;ng nguy hiểm, h&amp;agrave;ng cấm&lt;/li&gt;
&lt;li&gt;Đe dọa, x&amp;uacute;c phạm, x&amp;acirc;m phạm&lt;/li&gt;
&lt;/ol&gt;

I don't know if function helper xml_convert will add trim and remove all spaces in the future


  20 Rules to Optimize PHP for High-Traffic Websites
Posted by: php_rocs - 09-04-2024, 08:20 AM - Replies (1)

Very useful read. (DEV.TO) 20 Rules to Optimize PHP for High-Traffic Websites - DEV Community


  Routes going to somewhere I didn't set
Posted by: Tokioshy - 09-04-2024, 07:11 AM - Replies (4)

So, I recently facing an issue where I had a code:

PHP Code:
$routes->add('operator/edit/(:segment)''Admin/Operator::edit/$1'); 

That code means to using controller Operator, right? But instead, I got directed to the controller Admin (The main controller) instead the Operator controller (screenshot). But, I'm a bit confused when I change the routes to:

PHP Code:
$routes->add('admin/operator/edit/(:segment)''Admin/Operator::edit/$1'); 

It suddenly work properly. Showing the views instead the error just like the screenshot above. Here is the preview (screenshot) when it's work properly. And by the way, I was using

PHP Code:
$routes->group('admin', function ($routes) {



So the 2 routes above was inside the group. Here is the code for controller Operator and the views: https://srcb.in/NrGmkGXZ3T I don't know if that code and my explanation was enough but... Just let me know if you need more code or more my explanation to help me out, thanks!


  SEO friendly localised urls
Posted by: kcs - 09-04-2024, 04:58 AM - Replies (8)

Hi,
I am trying to improve my multilingual website, building on https://includebeer.com/en/blog/creating...r-4-part-1.
I would like to have my urls in the language of the page. For example, for a research page, have /en/research for english content and /fr/recherche for french. My routes are defined as such: 

Code:
$routes->get('/{locale}/research', 'PagesController::show/research', ['as' => 'research']);

I thought I could do this inside routes.php:
Code:
$routes->get('/en/research', 'PagesController::show/research', ['as' => 'enResearch']);
$routes->get('/fr/recherche', 'PagesController::show/research', ['as' => 'frResearch']);

And modify my menu to call for the right alias like that
Code:
<?= route_to($locale."Research") ?>

But then  I loose the locale, so if I am on the english version of the page and click on the link to view the page in French, I still see the english version (with the French url).
What would be the best approach to make SEO friendly urls in this case?


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

Username
  

Password
  





Latest Threads
Controller Filter Not Run...
by occitan
9 hours ago
Entity magic __get not ca...
by rockinmusicgv
Yesterday, 12:17 PM
Extending class Config\Au...
by ozornick
Yesterday, 08:06 AM
CodeIgniter v4.5.5 bug fi...
by InsiteFX
09-07-2024, 10:00 PM
Routing POST instead post
by kenjis
09-07-2024, 07:23 PM
How does $allowedFields p...
by kenjis
09-06-2024, 04:56 PM
Accessing Shield User ent...
by evansharp
09-06-2024, 04:21 PM
futurism.com. Human Deve...
by Renta Ardhana
09-06-2024, 04:49 AM
File not found on my onli...
by JulienB
09-06-2024, 01:03 AM
SEO friendly localised ur...
by InsiteFX
09-05-2024, 09:52 PM

Forum Statistics
» Members: 103,027
» Latest member: songhoalonggroup
» Forum threads: 77,948
» Forum posts: 377,775

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB