-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Simple view
Category:Library::Community | Category:Library::Template Engine
(abandoned code)
Looking at the other template libraries and the native CI way of displaying pages i didn't find anything that was easy to use and yet powerful enough to handle complex lay-outs.
I didn't want to restrict developers to use a formatted file structure or a database. the only thing the library needs are the two library files and a config file.
13-10-2007 For the 1.5 version i added controller support for partials and i removed the ci_replace function.
Controller support for partials was something i wanted after a topic i was discussing in the forum. The implementation is rough but it works.
Having controller support there is no need to write placeholder strings in the config array for CI functionality.
I have also renamed the view function and added another.
This is the main library file. The class methods:
-
view (viewpage in 1.5) : which you use in the controllers to display the layout you want. f
-
viewpart (1.5) : to display partials.
-
ci_replace (removed in 1.5) : this is a helper function to get data from various CI resources defining them in the config file. For now it supports: -- config->item() use : ConfigItem-xxx| -- argumentless config functions use : ConfigFunct-xxx| -- argumentless uri functions use : UriFunct-xxx| -- session->userdata() use : SessionItem-xxx|
This file contains one method that is used in the main library file:
- items : it looks for similar named variables in the config array using a regular expression
This file holds all the configuration variables.The variable names are divided into sections using an underscore. The variables are divided into three sections : page parts, general variables and partial variables
- Part parts : there are two prefixes used: -- partials_ : this is a comma delimited string which holds the variable names used in the master pages. The second part has to be the file name of the master view file, for example```php $config['partials_layout'] = 'header,main,footer';
-- **part_** : these variables define the default view files, for example ```php
$config['part_main'] = 'main';
1.5 behaviour for part_ : use the prefixes view/ and ctrl/ for the value.
$config['part_main'] = 'view/main';
- general and partial variables : the prefix used for these variables is var_. A general variable has 3 sections and a partial variables 4. the second section is the master view file and the third section is the partial view file. The last section is always the variable name used in the view file(s). general example :
$config['var_layout_pagetitle'] = 'Welcome';
partial example :
$config['var_layout_main_title'] = 'Hello';
The general variable gets overwritten by the partial variable with the same name and the partial variable gets overwritten by the controller variable for that partial.
// config
$config['var_layout_title'] = 'Hello';
$config['var_layout_main_title'] = 'Hello partial';
// controller
$vars['main']['title'] = 'Hello controller';
// shows Hello controller
tip : if you have several variables with the same content or same filestructure make a variable and use that instead of defining each variable seperate.
$emptystr = '';
$config['var_layout_main_input1'] = $emptystr;
$config['var_layout_main_input2'] = $emptystr;
$deepview = 'folder1/folder2/folder3/view';
$config['var_layout_'.deepview.'_input1'] = '';
$config['var_layout_'.deepview.'_input2'] = '';
As this master view file is defined as default in the library. For now the master view file can only be changed in the controllers.
I explained the use of the config file above so now we are going to explore how to view all that configuring on the website.
In the config/autoload.php file add Simpleview to the libraries array and simpleview to the config array.
To view the page with the default configuration just add
$this->simpleview->view();
1.5
$this->simpleview->viewpage();
The view method has two arguments: $vars and $parts
- $vars is an array that can be used for general and partial variables. General variables have as the first key an empty string, for the partial variables the first key is the variable name used in the master view file. The second key is the variable name.
$var['']['pagetitle'] = 'Welcome 2';
$var['main']['input1'] = 'name';
- $parts is an array where the first key is the variable name used in the master view file. A predefined variable master is used to switch the master view file.
$parts['main'] = 'main2';
$parts['master'] = 'layout2';
1.5
$parts['main'] = 'view/main2';
$parts['master'] = 'layout2';
the $vars array is the first argument and the $parts array the second.
- You can't use underscores in folder- and filenames
- page caching
- Add argument to the view method to automatically change the view files if someone has got a different status.
- better controller support code
1.5.0 File:simpleview1.5.0.zip
- controller partials support
- ci_replace function removed 1.0.1 File:simpleview1.0.1.zip
- Changed libraries/Simpleview.php to allow the master view file in folders 1.0.0 File:simpleview.zip