CodeIgniter Forums
Type error in SYSTEMPATH\View\Cells\Cell.php at line 88 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Type error in SYSTEMPATH\View\Cells\Cell.php at line 88 (/showthread.php?tid=90694)



Type error in SYSTEMPATH\View\Cells\Cell.php at line 88 - DXArc - 04-19-2024

I got a type error in SYSTEMPATH\View\Cells\Cell.php at line 88:
substr(): Argument #3 ($length) must be of type ?int, bool given
because of
declare(strict_types=1);
I changed the code to:
            $pos = strrpos($viewName, '_cell');
            if ($pos === false) {
              $possibleView1 = $directory . $viewName . '.php';             
            } else {
              $possibleView1 = $directory . substr($viewName, 0, $pos) . '.php';
            }

Now the gallery using Cell.php is working. I hope it helps.


RE: Type error in SYSTEMPATH\View\Cells\Cell.php at line 88 - kenjis - 04-20-2024

Thank you. But how to reproduce the error?


RE: Type error in SYSTEMPATH\View\Cells\Cell.php at line 88 - DXArc - 04-21-2024

(04-20-2024, 02:27 AM)kenjis Wrote: Thank you. But how to reproduce the error?
The error is in Codeigniter 4.5.1. I did not use version 4.5.0.

I use in app/Cells/GalleryItem.php the following code:

<?php

namespace App\Cells;

use CodeIgniter\View\Cells\Cell;

class GalleryItem extends Cell
{
    public $group;
    public $wrap;
    public $overlay;
    public $item;
    public $col;
    public $margin;
    public $imagepath;
    public $image;
    public $imagealt;
    public $imagebig;
}

and in app/Cells/gallery_item.php:

<div class="<?= $item; ?> <?= $col; ?> <?= $margin; ?>">
  <div class="<?php print($wrap); ?>">
    <img src="<?php print($imagepath . '/' . 'thumb/' . $image); ?>" alt="<?php print($imagealt); ?>" class="img-responsive">
    <div class="<?php print($overlay); ?>">
      <a href="<?php print($imagepath . '/' . 'big/' . $imagebig); ?>" data-lightbox="<?= $group; ?>">
        <span></span>
      </a>
    </div>
  </div> <!--img-wrap-->     
</div><!--item-->

This is called from a view with

<?= view_cell('App\Cells\GalleryItem', [
    'group'    => 'examplegroup',
    'wrap'      => 'item-img-wrap',
    'overlay'  => 'item-img-overlay',
    'item'      => 'mix',
    'col'      => 'col-sm-4',
    'margin'    => 'margin30', 
    'imagepath' => '/assets/images/gallery',
    'image'    => 'example-th.jpg',
    'imagealt'  => 'Example',
    'imagebig'  => 'example.jpg',
]); ?>

Combined with Michelf markdown I use Codeigniter as a flatfile CMS. It substitutes another flatfile CMS. No need of other third party code except for markdown.


RE: Type error in SYSTEMPATH\View\Cells\Cell.php at line 88 - kenjis - 04-22-2024

Your code does not follow the convention.

Quote:By convention, the class name should be in PascalCase suffixed with Cell and the view should be the snake_cased version of the class name, without the suffix. For example, if you have a MyCell class, the view file should be my.php.
https://codeigniter4.github.io/CodeIgniter4/outgoing/view_cells.html#controlled-cells



RE: Type error in SYSTEMPATH\View\Cells\Cell.php at line 88 - DXArc - 04-23-2024

Thank you. That works. I think I got the example from another site.