Welcome Guest, Not a member yet? Register   Sign In
How to create custom view folder
#1

(This post was last modified: 04-17-2020, 07:00 PM by Chivinsdev.)

Hello friends,
Please I want someone to help me on this.
I am trying to change the view folder to something else like "themes". And I will like this folder to be in the root directory.
I try using namespace to point the themes folder in the root directory i discovered you must create another folder name "Views" into the themes folders.

Here is what I need when I use the namespace to point to home.php

Codeigniter4 root directory => themes => home.php

instead of this

Codeigniter4 root directory => themes => Views => home.php.

I try this but not working

PHP Code:
function view(string $name, array $data = [], array $options = []): string
    
{
        /**
         * @var CodeIgniter\View\View $renderer
         */
        $renderer Services::renderer('themes'); // I try to change the directory viewPath but not working

        $saveData true;
        if (array_key_exists('saveData'$options) && $options['saveData'] === true) {
            $saveData = (bool) $options['saveData'];
            unset($options['saveData']);
        }

        return $renderer->setData($data'raw')
            ->render($name$options$saveData);
 } 


I will always appreciate your help. Thanks
Reply
#2

IIRC the renderer service is instantiated earlier in the process, so the shared copy in the app has app/Views as its view folder. I believe all you need to do is request a non-shared instance of the renderer and it should work. You can see a working example over on the forum project I've started.

PHP Code:
$renderer Services::renderer(ROOTPATH .'/themes/'nullfalse); 
Reply
#3

(04-17-2020, 08:50 PM)kilishan Wrote: IIRC the renderer service is instantiated earlier in the process, so the shared copy in the app has app/Views as its view folder. I believe all you need to do is request a non-shared instance of the renderer and it should work. You can see a working example over on the forum project I've started.

PHP Code:
$renderer Services::renderer(ROOTPATH .'/themes/'nullfalse); 


Thank you very much you just saved my life on my project. And you still show your perfect working as a good leader after the formal i always disturb both in github and forum. Thanks a lot
Reply
#4

(This post was last modified: 04-20-2020, 09:07 AM by jekslek. Edit Reason: spelling )

(04-17-2020, 06:09 PM)Chivinsdev Wrote: Hello friends,
Please I want someone to help me on this.
I am trying to change the view folder to something else like "themes". And I will like this folder to be in the root directory.
I try using namespace to point the themes folder in the root directory i discovered you must create another folder name "Views" into the themes folders.

Here is what I need when I use the namespace to point to liteblue home.php

Codeigniter4 root directory => themes => home.php

instead of this

Codeigniter4 root directory => themes => Views => home.php.

I try this but not working

PHP Code:
function view(string $name, array $data = [], array $options = []): string
    
{
        /**
         * @var CodeIgniter\View\View $renderer
         */
        $renderer Services::renderer('themes'); // I try to change the directory viewPath but not working

        $saveData true;
        if (array_key_exists('saveData'$options) && $options['saveData'] === true) {
            $saveData = (bool) $options['saveData'];
            unset($options['saveData']);
        }

        return $renderer->setData($data'raw')
            ->render($name$options$saveData);
 } 


I will always appreciate your help. Thanks
I am still facing the same issue. Did you really find a solution?
Reply
#5

(04-19-2020, 05:51 AM)jekslek Wrote:
(04-17-2020, 06:09 PM)Chivinsdev Wrote: Hello friends,
Please I want someone to help me on this.
I am trying to change the view folder to something else like "themes". And I will like this folder to be in the root directory.
I try using namespace to point the themes folder in the root directory i discovered you must create another folder name "Views" into the themes folders.

Here is what I need when I use the namespace to point to liteblue home.php

Codeigniter4 root directory => themes => home.php

instead of this

Codeigniter4 root directory => themes => Views => home.php.

I try this but not working

PHP Code:
function view(string $name, array $data = [], array $options = []): string
    
{
        /**
         * @var CodeIgniter\View\View $renderer
         */
        $renderer Services::renderer('themes'); // I try to change the directory viewPath but not working

        $saveData true;
        if (array_key_exists('saveData'$options) && $options['saveData'] === true) {
            $saveData = (bool) $options['saveData'];
            unset($options['saveData']);
        }

        return $renderer->setData($data'raw')
            ->render($name$options$saveData);
 } 


I will always appreciate your help. Thanks
I am still facing the same issue. Did you really find a solution?

Yes i find a solution to it. sorry for my late responds. I have being having issue login in into my account in this forum
Reply




Theme © iAndrew 2016 - Forum software by © MyBB