Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14343 articles
Browse latest View live

Analyzing Design Patterns in CodeIgniter 4

$
0
0
CodeIgniter 4 employs several design patterns to enhance code organization, reusability, and maintainability. Here my note of the (7+2) prominent patterns:

1. Singleton Pattern
Purpose: Ensures that a class has only one instance and provides a global point of access to it.
Usage: CodeIgniter's CI_Loader class is a classic example of a singleton. It's used to load other classes and components within the framework.

2. Dependency Injection
Purpose: Promotes loose coupling between classes by passing dependencies as parameters to constructors or methods.
Usage: CodeIgniter uses dependency injection to inject necessary services into controllers and other classes. For instance, a controller might be injected with a database connection or a session handler.

3. Front Controller Pattern
Purpose: Centralizes request handling and routing.
Usage: The index.php file in CodeIgniter acts as the front controller. It intercepts all incoming requests, routes them to the appropriate controller, and handles the response.

4. Model-View-Controller (MVC) Pattern  Big Grin
Purpose: Separates concerns into three interconnected components: Model (data), View (presentation), and Controller (logic).
Usage: CodeIgniter adheres to the MVC architecture. Controllers handle user requests, models interact with data, and views present the output.

5. Observer Pattern
Purpose: Defines a one-to-many dependency between objects, so that when one object changes state, all its dependents are notified and updated automatically.
Usage: While not explicitly implemented in CodeIgniter's core, the observer pattern can be used to implement features like caching or event handling.

6. Factory Pattern
Purpose: Provides a way to create objects without specifying their exact class.
Usage: CodeIgniter's CI_Loader class can be seen as a factory for creating instances of other classes based on their names.

7. Facade Pattern
Purpose: Provides a unified interface to a set of interfaces in a subsystem.
Usage: While not a direct implementation, CodeIgniter's CI_Loader class can be considered a facade, simplifying the process of loading and accessing various components.

Additional:
- Middleware: CodeIgniter's middleware functionality can be seen as an application of the Chain of Responsibility pattern.
- Routing: The routing system in CodeIgniter employs a combination of patterns, including the Strategy pattern for different routing methods and the Composite pattern for grouping routes.

Are you interested in diving deeper into CodeIgniter 4 patterns used?

Calendar Sync Challenges

$
0
0
Has anyone here dealt with syncing calendars across different platforms? I’ve been wrestling with this lately, and it's a bit of a headache getting everything to stay in sync. I’ve tried a few methods, but they all seem to have their quirks.
Wondering if there are any tried-and-true methods or tools that have worked well for you all. Also, any advice on how to integrate something like this with CodeIgniter would be appreciated.

Routes regular expressions?

$
0
0
Hello. I wanted to make a routing with a regular expression that allows for number range 100 - 672 (100, 101, 102 ... 671, 672). I tried this example, for Numbers range 100 - 699.
How can I change this?
Thanks for your help.

routes.php
PHP Code:
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

// http://localhost:8888/domain/text-text-text/123
// Now only for Numbers  range 100 - 699
$route['(:any)/([1-6][0-9][0-9])'] = "category/index/$1"

How to get the rowCount with results returned by query while joining tables

$
0
0
Hi

I am using CI4 with SHIELD.
I have created a function to get the list of users with multiple dynamic filters and also joined with many tables with pagination, It's working fine.
I want to get the count of total number of results returned by the query. I have tried many codes to achieve this, because of  using group by clause, I was getting issues. 
Finally I achieve what I needed, But I am not sure if it is correct way or not. currently it's only 50 records but it's taking much time to load. Please suggest if there is any better way.
Here is my code
PHP Code:
function getPlayers($whereClause = [], $metaQuery = [], $search ''$orderBy ''$order ''$limit 10$offset 0$noLimit false) {
    $db = \Config\Database::connect();

    $flagPath =  base_url() . 'uploads/logos/';

    // Start building the main query
    $builder $db->table('users');
    $builder->select'users.*, 
                        user_roles.role_name as role_name,
                        languages.language as language,
                        domains.domain_name as domain_name,
                        domains.location as user_location,
                        auth.secret as email,
                        packages.title as package_name,
                        pm.last4 as last4,
                        pm.brand as brand,
                        pm.exp_month as exp_month,
                        pm.exp_year as exp_year,
                        us.status as subscription_status,
                        us.plan_period_start as plan_period_start,
                        us.plan_period_end as plan_period_end,
                        us.plan_interval as plan_interval,
                        us.coupon_used as coupon_used,
                        CASE
                            WHEN TIMESTAMPDIFF(SECOND, `users`.`last_active`, NOW()) < 60 THEN 
                                CONCAT(TIMESTAMPDIFF(SECOND, `users`.`last_active`, NOW()), " secs ago")
                            WHEN TIMESTAMPDIFF(MINUTE, `users`.`last_active`, NOW()) < 60 THEN 
                                CONCAT(TIMESTAMPDIFF(MINUTE, `users`.`last_active`, NOW()), " mins ago")
                            WHEN TIMESTAMPDIFF(HOUR, `users`.`last_active`, NOW()) < 24 THEN 
                                CONCAT(TIMESTAMPDIFF(HOUR, `users`.`last_active`, NOW()), " hours ago")
                            WHEN TIMESTAMPDIFF(DAY, `users`.`last_active`, NOW()) < 30 THEN 
                                CONCAT(TIMESTAMPDIFF(DAY, `users`.`last_active`, NOW()), " days ago")
                            WHEN TIMESTAMPDIFF(MONTH, `users`.`last_active`, NOW()) < 12 THEN 
                                CONCAT(TIMESTAMPDIFF(MONTH, `users`.`last_active`, NOW()), " months ago")
                            ELSE 
                                CONCAT(TIMESTAMPDIFF(YEAR, `users`.`last_active`, NOW()), " years ago")
                        END AS last_activity_time,

                        CASE
                            WHEN TIMESTAMPDIFF(SECOND, `users`.`created_at`, NOW()) < 60 THEN 
                                CONCAT(TIMESTAMPDIFF(SECOND, `users`.`created_at`, NOW()), " secs ago")
                            WHEN TIMESTAMPDIFF(MINUTE, `users`.`created_at`, NOW()) < 60 THEN 
                                CONCAT(TIMESTAMPDIFF(MINUTE, `users`.`created_at`, NOW()), " mins ago")
                            WHEN TIMESTAMPDIFF(HOUR, `users`.`created_at`, NOW()) < 24 THEN 
                                CONCAT(TIMESTAMPDIFF(HOUR, `users`.`created_at`, NOW()), " hours ago")
                            WHEN TIMESTAMPDIFF(DAY, `users`.`created_at`, NOW()) < 30 THEN 
                                CONCAT(TIMESTAMPDIFF(DAY, `users`.`created_at`, NOW()), " days ago")
                            WHEN TIMESTAMPDIFF(MONTH, `users`.`created_at`, NOW()) < 12 THEN 
                                CONCAT(TIMESTAMPDIFF(MONTH, `users`.`created_at`, NOW()), " months ago")
                            ELSE 
                                CONCAT(TIMESTAMPDIFF(YEAR, `users`.`created_at`, NOW()), " years ago")
                        END AS registration_time,

                        JSON_ARRAYAGG(
                            JSON_OBJECT(
                                "country_name", c.country_name, 
                                "flag_path", CONCAT("'
.$flagPath.'", c.country_flag)
                            )
                        ) AS user_nationalities
                    '
);

    

    $builder
->join('(SELECT user_id, secret FROM auth_identities WHERE type = "email_password") auth''auth.user_id = users.id''LEFT');
    $builder->join('user_roles''user_roles.id = users.role''INNER');
    $builder->join('languages''languages.id = users.lang''INNER');
    $builder->join('domains''domains.id = users.user_domain''INNER');
    $builder->join('user_nationalities un''un.user_id = users.id''LEFT');
    $builder->join('countries c''c.id = un.country_id''LEFT');
    $builder->join('(SELECT user_id, brand, exp_month, exp_year, last4 FROM payment_methods WHERE is_default = 1) pm''pm.user_id = users.id''LEFT');

    // START: membership check
    if (isset($whereClause['membership'])){

        if($whereClause['membership'] == 'paid'){
            $builder->join('(SELECT id as max_id, user_id, status, package_id, plan_period_start, plan_period_end, plan_interval, coupon_used FROM user_subscriptions WHERE id IN (SELECT MAX(id) as max_id FROM user_subscriptions GROUP BY user_id) AND status = "active") us''us.user_id = users.id''INNER');
        } else {
            $builder->join('user_subscriptions us''us.user_id = users.id''LEFT');
        }

    } else {
        $builder->join('(SELECT id as max_id, user_id, status, package_id, plan_period_start, plan_period_end, plan_interval, coupon_used FROM user_subscriptions WHERE id IN (SELECT MAX(id) as max_id FROM user_subscriptions GROUP BY user_id)) us''us.user_id = users.id''LEFT');
    }
    // END: membership check


    $builder->join('packages''packages.id = us.package_id''LEFT');

    $builder->where('users.deleted_at'NULL);

    // Build the query with the same conditions
    if (isset($whereClause) && count($whereClause) > 0) {
        foreach ($whereClause as $key => $value) {
            if ($key == 'membership') {
                continue;
            } elseif ($key == 'email') {
                $builder->like("auth.secret"$value);
            } elseif ($key == 'location') {
                $builder->like("domains.id"$value);
            /*elseif ($key == 'last_active') {
                $builder->where("users.last_active >= ", ( CURDATE() " - INTERVAL". $value ));
            } */ 
else {
                $builder->where("users.$key"$value);
            }
        }
    }

    if (isset($metaQuery) && count($metaQuery) > 0) {
        foreach ($metaQuery as $meta) {
            $metaBuilder $db->table('user_meta');
            $metaBuilder->select('user_id')
                        ->where('meta_key'$meta['meta_key']);
            
            $metaValue 
is_array($meta['meta_value']) ? $meta['meta_value'] : (is_numeric($meta['meta_value']) ? (int)$meta['meta_value'] : $meta['meta_value']);
            
            
if ($meta['operator'] == "=") {
                $metaBuilder->where('meta_value'$metaValue);
            } elseif ($meta['operator'] == ">=") {
                $metaBuilder->where('meta_value >='$metaValue);
            } elseif ($meta['operator'] == "<=") {
                $metaBuilder->where('meta_value <='$metaValue);
            } elseif ($meta['operator'] == "IN") {
                $metaBuilder->whereIn('meta_value'$metaValue);
            } else {
                $metaBuilder->like('meta_value'$metaValue);
            }

            $metaSubquery $metaBuilder->getCompiledSelect();
            $builder->where("users.id IN ($metaSubquery)");
        }
    }

    // START: membership check
    // check only users with free membership
    if (isset($whereClause['membership']) && $whereClause['membership'] == 'free'){
        $builder->where("us.user_id"NULL);
    }
    // END: membership check


    if (isset($search) && !empty($search)) {
        $builder->groupStart();
            $builder->orLike('users.username'$search);
            $builder->orLike('users.first_name'$search);
            $builder->orLike('users.last_name'$search);
            $builder->orLike('auth.secret'$search);
        $builder->groupEnd();
    }

    $builder->groupBy('users.id');
    
    
// Count the total number of results
    $countBuilder  $db->newQuery()->select('count(*) as total_count')->fromSubquery($builder'counter_table');
    $countQuery $countBuilder->get();
    $totalCount $countQuery->getRow()->total_count;


    // Add Sorting
    if (!empty($orderBy)) {
        $builder->orderBy($orderBy$order);
    } else {
        $builder->orderBy('id''DESC');
    }

    // Add pagination
    if ($noLimit != true) {
        $builder->limit($limit$offset);
    }

    // Execute the main query
    $query $builder->get();
    // echo '>>>>>>>> getLastQuery >>>>> '. $db->getLastQuery(); exit;

    $result $query->getResultArray();

    // Process the results to merge metadata into user objects
    $users = [];
    foreach ($result as $row) {
        $userId $row['id'];
        if (!isset($users[$userId])) {
            $users[$userId] = [
                'id'                            => $row['id'],
                'username'                      => $row['username'],
                'email'                        => $row['email'],
                'created_at'                    => $row['created_at'],
                'updated_at'                    => $row['updated_at'],
                'first_name'                    => $row['first_name'],
                'last_name'                    => $row['last_name'],
                'role_name'                    => $row['role_name'],
                'language'                      => $row['language'],
                'newsletter'                    => $row['newsletter'],
                'user_domain'                  => $row['domain_name'],
                'user_location'                => $row['user_location'],
                'last_active'                  => $row['last_active'],
                'status'                        => $row['status'],
                'last4'                        => $row['last4'],
                'brand'                        => $row['brand'],
                'exp_month'                    => $row['exp_month'],
                'exp_year'                      => $row['exp_year'],
                'package_name'                  => $row['package_name'],
                'subscription_status'          => $row['subscription_status'],
                'plan_period_start'            => $row['plan_period_start'],
                'plan_period_end'              => $row['plan_period_end'],
                'plan_interval'                => $row['plan_interval'],
                'coupon_used'                  => $row['coupon_used'],
                'last_activity_time'            => $row['last_activity_time'],
                'user_nationalities'            => $row['user_nationalities'],
                'registration_time'            => $row['registration_time'],
                'meta' => []
            ];
        }
    }

    $imagePath base_url() . 'uploads/';

    // Get all meta data for each user
    $userIds array_keys($users);
    if (!empty($userIds)) {
        $metaBuilder $db->table('user_meta');
        $metaBuilder->whereIn('user_id'$userIds);
        $metaQuery $metaBuilder->get();
        $metaResult $metaQuery->getResultArray();

        foreach ($metaResult as $metaRow) {
            //pr($metaRow);
            $userId $metaRow['user_id'];
            $users[$userId]['meta'][$metaRow['meta_key']] = $metaRow['meta_value'];
            if($metaRow['meta_key'] == 'profile_image'){
                $users[$userId]['meta']['profile_image_path'] = $imagePath.$metaRow['meta_value'];
            }
            if($metaRow['meta_key'] == 'cover_image'){
                $users[$userId]['meta']['cover_image_path'] = $imagePath.$metaRow['meta_value'];
            }
        }
    }

    $userData array_values($users);
    return [
        'totalCount' => $totalCount,
        'users' => $userData
    
];


Earlier I was using this code to get the Count, it was working fine, but not working after I added "GROUP BY"
PHP Code:
// Count the total number of results
    $countBuilder = clone $builder;
    $countBuilder->select('COUNT(*) as total_count');
    $countQuery $countBuilder->get();
    $totalCount $countQuery->getRow()->total_count

Also tried below code
PHP Code:
//Count the total number of results
$countBuilder = clone $builder;
$countBuilder->getCompiledSelect(true);
$countBuilder->select('COUNT(DISTINCT users.id) as total_count'false); // Use COUNT DISTINCT to ensure accurate counting
$countQuery $countBuilder->get();
$totalCount $countQuery->getRow()->total_count;
// above returns "SELECT COUNT(DISTINCT users.id) as total_count FROM `users`;" query. skipped all the filters and I got total number of rows in table instead of total number of rows retuned by query 


// also tried this
$countBuilder->resetSelect(); // Reset the SELECT clause
// got CRITICAL Error: Call to protected method CodeIgniter\Database\BaseBuilder::resetSelect() from global scope 

Thanks

Upload pdf file fails

$
0
0
I try upload file image and working fine, but why not work with pdf file?
i got error "The file requirement is not a valid uploaded file". whats wrong?

PHP Code:
$validationRule = [
            'file' => [
                'label' => 'File Upload',
                'rules' => [
                    'uploaded[file]',
                    'mime_in[file,application/pdf,application/force-download,application/x-download]',
                    'max_size[file,5120]',
                ],
            ],
        ];
        if (! $this->validate($validationRule)) {
            $errors $this->validator->getErrors();
            $error array_shift($errors);

            dd($error);
        

after dd($file = $this->request->getFile('file')); originalMimeType is empty string.

[Image: Screenshot-2024-09-01-at-20-55-54.png]

Accessing Shield User entity properties

$
0
0
When I use the helper and reference 

PHP Code:
auth()->user()->attributes 


it's always NULL.

If I dd() or var_dump() auth()->user() though, it shows $attributes is an array with juicy values like 'username'. How do I get that juice?

Also, where did the forum search go?

Happy Labor Day Everyone.

Codeigniter can not find the view file [SOLVED]

$
0
0
in linux server i faced error as follow:

[Image: Screenshot-2024-09-03-at-07-19-52.png]

here my config:

[Image: Screenshot-2024-09-03-at-07-20-54.png]

The configuration works fine on local machine but not on the linux server, what's the cause? Looking for help.
Thanks in advance.

Solved! The problem is linux case sensitive.

DEV.to - Understanding Web Storage: LocalStorage, SessionStorage, and Cookies

Lib Validation : permit empty string for valid_email or extend rule

$
0
0
Hello everyone, I want to use validation for mail field which is not required. But empty string is not validated. Is there a method to validate it anyway ?
Or the other option I think is to custom the predefined rule "valid_email", is it possible ?
In advance, thank you.

How does $allowedFields protect against mass assignment vulnerabilities?

$
0
0
I thought I understood $allowedFields until recently, when I tried to insert a field not listed by assigning it manually to my entity.
Turns out that it is discarded, even though I assigned it manually, ej:

PHP Code:
$obj->protectedField 'value'

and then

PHP Code:
$objModel->insert($obj); 

It seems that I can't set any field unless it's on the $allowedFields list. This will only protect fields that are automatically handled by the database or inserted bypassing $allowedFields.

Could you please clarify whether I've misunderstood or if there's something I'm missing?

SEO friendly localised urls

$
0
0
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?

Routes going to somewhere I didn't set

$
0
0
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!

20 Rules to Optimize PHP for High-Traffic Websites

xml_convert error in long space and end content in javascript 4.5.4

$
0
0
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

futurism.com. Human Developers Will Soon Be a Thing of the Past

CodeIgniter v4.5.5 bug fix released

Routing POST instead post

$
0
0
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]

Extending class Config\Autoload

$
0
0
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 

Entity magic __get not called in second generation child class

$
0
0
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.
Viewing all 14343 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>