Welcome Guest, Not a member yet? Register   Sign In
Type error in SYSTEMPATH\View\Cells\Cell.php at line 88
#1

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.
Reply
#2

Thank you. But how to reproduce the error?
Reply
#3

(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.
Reply
#4

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/CodeIgnit...lled-cells
Reply
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB