Welcome Guest, Not a member yet? Register   Sign In
Thoughts on sending data to library from view
#3

(12-17-2020, 12:05 AM)bivanbi Wrote: Since you can call view from within a view, you can make the decision what other ('sub') views to load there.

Example: Views/users/list.php

PHP Code:
<?php /** @var ViewData $data */ ?><!DOCTYPE html>
<html lang="en">
<?= view($data->theme->getHeaderViewName(), ['data' => $data]) ?>
<?= view
($data->theme->getBodyViewName(), ['data' => $data]) ?>
<?= view
($data->theme->getFooterViewName(), ['data' => $data]) ?>
</html> 


Its not the matter of knowing how to do it, i have a working example. Plus there is no need to re-invent the wheel im using codeigniters default way of building the templates out like

Code:
$this->extend(theme_url('layouts/main'));
$this->section('content');

The question is more specific to 'should it be done' as it doesn't strictly follow MVC pattern. My whole concern is if i define what dependencies a particular page may need, i.e css and js files in the controller, then any additional themes created would need modifications made to the controller.

Instead i propose that the dependencies are loaded from within the view file. In our 'header' template we may have already defined our site wide css file, in our 'footer' template file we have defined our site wide specific js file(s). Now if a particular page needed additional dependencies we load directly from view (such as 'customers') that is wrapped with our header and footer template files and the included files get injected to the header or footer respectively, instead of from the controller, allowing theme designers to design the theme and thus becomes a drop in replacement with no modification to the core code of the application.
Reply


Messages In This Thread
RE: Thoughts on sending data to library from view - by Geeklabs - 12-17-2020, 03:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB