Welcome Guest, Not a member yet? Register   Sign In
Shield problem with a view that extends a layout
#1

Hi all, I'm new here and I'm a beginner with CI..
I have Shield installed and I noticed that it only works if the view is simple and doesn't extend a layout.
My Auth.php, AuthGroups.php are the default ones.

Filters.php (customized part only):
PHP Code:
public array $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
            // 'invalidchars',
            'session' => ['except' => ['login*''register''auth/a/*']],
        ],
        'after' => [
            'toolbar',
            // 'honeypot',
            // 'secureheaders',
        ],
    ]; 

Routes.php:
PHP Code:
$routes->get('/''Example::index');

service('auth')->routes($routes); 

Example.php (controller):
PHP Code:
namespace App\Controllers;

class 
Example extends BaseController
{
    public function index()
    {
        return view('example');
    }


1) example.php (view, without layout):
PHP Code:
<h3>Example page</h3

2) example.php (view, if it extends a layout):
PHP Code:
<?= $this->extend('layout'?>
<?= $this
->section('content'?>
<h3>Example page</h3>
<?= $this->endSection() ?>

With the view 1), after logging in, I get the user logged in.
With the view 2) the view is displayed but the user remains not logged in (even if he has entered the correct credentials).
What's wrong? Thanks.






Reply
#2

(05-14-2023, 10:37 AM)SalDeF Wrote: 2) example.php (view, if it extends a layout):

Hi @SalDeF, Apparently I understand that you intend to customize the controller. If this is your intention, please read extending-the-controllers because the provided codes are not the same as the instructions.

However, I am just answering your question. Proceed as follows:

PHP Code:
<?= $this->extend(config('Auth')->views['layout']) ?>
<?= $this
->section('main'?>
<h3>Example page</h3>
<?= $this->endSection() ?>
Reply
#3

(09-03-2023, 12:12 PM)datamweb Wrote:
(05-14-2023, 10:37 AM)SalDeF Wrote: 2) example.php (view, if it extends a layout):

Hi @SalDeF, Apparently I understand that you intend to customize the controller. If this is your intention, please read extending-the-controllers because the provided codes are not the same as the instructions.

However, I am just answering your question. Proceed as follows:

PHP Code:
<?= $this->extend(config('Auth')->views['layout']) ?>
<?= $this
->section('main'?>
<h3>Example page</h3>
<?= $this->endSection() ?>
Thank you @datamweb for the answer. Unfortunately, since I couldn't solve the problem on my own, before your response arrived I switched to using a python-based framework to develop my web app. I hope your answer can help others ;-)
Reply
#4

I have this same issue, and when I try your solution I get the following error msg Undefined array key "layout"
same as the other user I am trying to use CodeIgniter layouts view and shield keeps the session data if you just
use a normal view but it does not keep the session data if you use a layout view
any help is appreciated, tis
Reply




Theme © iAndrew 2016 - Forum software by © MyBB