Ness PHP Content Management
Required Namespace
  • Ness
    • ContentManager

You can include this library to your code file by typing the below code;

use Ness\ContentManager


About Content Manager Class #top

Ness PHP contains a class for managing contents of your application easily. using this class you can access different contents from anywhere in your code. For example you are designing a master page and you need to include style sheets and javascript in your page, you can copy the related css and js file in the Content directory and access them easily with just a single line. Content Manager class will help you the problem with relative file paths. Please continue reading this page to get more information about Content Manager class and methods available in Content Manager class.


Directories for Contents #top

Content folder can be found in [project_dir]/Application/ path. You can realise there is folder called 'Content' in main 'Application' directory with few sub directories. This sub directories will help you split the files from each other and get rid of the complexity.

Here is a short description for each sub folder in 'Content' directory;


css: This folder is preset for holding your style sheets. You can add all your .css file in that folder. Also you can create subfolders for multiple css files like bootstrap etc.

img: You can import all your project's image assets here like logo, headers etc for using later.

js: js path is present to store all your javascript code files, like in css path you can create sub-folders.

uploads: This folder is created for generating a valid upload path. You can use this with Forms/FileUpload class.

widget: Import various html or php code snippets from this path easily.


Diffrences Between Resources & Content Manager #top

Ness PHP contains two different libraries for content management. One of them is the Resource class which is described in previous topics and the other one is ContentManager class which is described and tutoried in this page.

These two libraries may look same in logic but there are some diffences in usage. For example Resource class (which is described previously) is designed to use and fit with string values, and the content manager class is more suitable to use with project assets like css,js, headers, logos etc.


Available Methods #top

getImage
ContentManager::getImage(string $filename);
This function returns the filename from the path {Application}\Content\img\{$filename}
Return String
Parameters $filename String; Filename of the img file.



getStyleSheet
ContentManager::getStyleSheet(string $filename);
This function returns the filename from the path {Application}\Content\css\{$filename}
Return String
Parameters $filename String; Filename of the css file.



getJavaScript
ContentManager::getJavaScript(string $filename);
This function returns the filename from the path {Application}\Content\js\{$filename}
Return String
Parameters $filename String; Filename of the js file.



getWidget
ContentManager::getWidget(string $filename);
This function returns the filename from the path {Application}\Content\widget\{$filename}
Return String
Parameters $filename String; Filename of the html/php file.



getFilePath
ContentManager::getFilePath(string $filename);
This function returns the filename from the path {Application}\Content\{$filename}
Return String
Parameters $filename String; Filename from the 'Content' folder. You can create own sub folders and use this function to include that file.



getUploadPath
ContentManager::getUploadPath(string $filename);
This function returns the filename from/in the path {Application}\Content\uploads\{$filename}
Return String
Parameters $filename String; Specified file name for new update to put in uploads path.



Example Usage of Content Manager #top

Assume that we are creating a master page in 'Template' folder and we have theese files;

  • style.css
  • bootstrap
  • loader.js
  • weather.php
we need to put files in the following folders;
style.css ----> css/style.css

bootstrap ----> css/bootstrap/*.css

loader.js ----> js/loader.js

weather.php ----> widget/weather.php



and write the following code lines in the Template/master_page.php;

    <?php
    	//Our master page to use later with view files in view inheritance.
    
    	use Ness\ContentManager as cm;
    ?>
    
    <!DOCTYPE html>
    <html>
    <head>
    	<title>New Application | Ness PHP</title>
    	<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<link rel="stylesheet" type="text/css" href="<?= cm::getStyleSheet("style.css") ?>">
    	<link rel="stylesheet" type="text/css" href="<?= cm::getStyleSheet("bootstrap".'/'."bootstrap.min.css")?>"> 
    	<script src="<?= cm::getJavaScript("loader.js")?>"></script>  
    </head>
    <body>
    
    <!--WEATHER WIDGET GET FROM THE WIDGET FOLDER-->
    
    <div class="weather">
    
    	<?php
    		$filename = cm::getWidget("weather.php");
    		include_once $filename;
    	?>
    </div>
    
    <?php 
    	/**
    	 * This line below must me available in all your master pages.
    	 * echo $this->contents; means your content place holder. Your data in
    	 * views will be loaded here.
    	 */
    	echo $this->contents;
    ?>
    
    </body>
    </html>