Skip to content

Placing view template outside of the 'Views' dir when using view() #180

Description

@sayonara90s

Dear Council...

I have a question.

Can I place view template outside Views dir when I am using view() function?

I have dir structure like this:

application/
.. Widgets/
.. .. Calendar/
.. .. .. Control.php
.. .. .. view.php

or

application/
.. OtherViews/

My problem:

Normally (getting an error), the path sould be reference:

.../application/Views/App\Widgets/calendar.php

related: System/Common.php line 146 - 151

        $file = $this->viewPath.$view;

        if (! file_exists($file))
        {
            $file = $this->loader->locateFile($view, 'Views');
        }

And my feature request:

I like the third param of view(), as far as I know that supported only one variable key (bool) $options['saveData'].

view(string $name, array $data, array $options)

I think wit adding 'default dir' can be solve the problem and optional.

$options = [
    'saveData' => true, // default 'not exists'
    'defaultDir' => 'Views' // default 'Views', this is my request... :)
];

With 'defaultDir' key, optional values:

  1. false or null, if I don't want to use 'Views' dir.
  2. dirname (string), for specific directory (I think this is not necessary).

Exm:

<?php namespace App\Widgets;

class Calendar {

    public function get()
    {
        return view('App\Widgets\Calendar\view', [], ['defaultDir' => '']);

        # ../application/Widgets/Calendar/view.php
    }

}

My widget combined with view_cell() (I like this feature, thanks!):

// non controller class
view_cell('App\Widgets\Calendar\control::get');

I think view() only work for the controller class (correct me if I'm wrong).
And, because it works perfect with my Blog module:

    application/
    modules/
    .. Blog/
    .. .. Controllers/
    .. .. Views/
    .. .. .. home.php
    view('Modules\Blog\home');

Hope you know what I mean.

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions