API VERSION 3 > Accessing UpdateCase from your CakePHP website

Connecting UpdateCase to your website is an easy process.

This goes through how to configure using client VERSION 3

# 1 > Initialization

Start by logging on to UpdateCase.com
Download the client
This will download a file (updateCase.php) to your downloads
Place this in the webroot of your project (app/webroot)

In the app_controller.php place the following in the beforeFilter()

require_once(APP.'webroot'.DS.'updateCase.php');$this->updateCase = new UpdateCase;$this->set('updateCase', $this->updateCase);
Configure::write("UpdateCase.variant_id", '###');

//Change ### to the variant number in UpdateCase.com

//Then define your language (it might be in a separate function 'setupLang' in the AppController

Configure::write('UpdateCase.language', 'eng');

//If you have a multi-lingual site, simple define per what language the site is currently in
if ($isENG) {
Configure::write('UpdateCase.language', 'eng');
} else {
Configure::write('UpdateCase.language', 'fre');

# 2 > Controller setup

Each action in the controller needs this call to initiate the page we are using:
Configure::write("UpdateCase.slug", 'Home');

# 3 > View (initiate)

VIEW: To initiate the view place this at the top of the page:
<?php $updateCase->loadPageBySlug(Configure::read("UpdateCase.slug")); ?>

-- OR -- you can specify a specific slug

<?php $updateCase->loadPageBySlug('Home'); ?>

# 4 > Single block of text

<?= $updateCase->getContentBy('Top','title'); ?>

# 5 > Groups

-Limited to a group
<?= $this->SetupCase->getContentBy('LOCATION', 'ELEMENT', 'GROUPNAME');

- - - GROUPS

After you create groups you can easily loop through them, by defining a LOCATION
<?php $groups = $updateCase->getGroupNamesByLocation("LOCATION"); ?>
<?php if ($groups): foreach ($groups as $group): ?>

<?= $updateCase->getContentBy("LOCATION", "ELEMENT", $group); ?>

<?php endforeach; endif; ?>

# 6 > Get Image

To add an image from UpdateCase; ADD this to an image tag

<img src="<?= $this->webroot; ?><?= $updateCase->getImage('LOCATION', 'ELEMENT', 'false', 'medium'); ?>" alt="name of pic here"/>

NOTE: medium is the size of the image and can be: medium OR thumb OR large

If you have a group:

<img src="<?= $this->webroot; ?><?= $updateCase->getImage('LOCATION', 'ELEMENT', '1', 'medium'); ?>" alt="name of pic here"/>

NOTE: 1 is the group number and can be changed per updateCase

-- OR if you want to create a image TAG with ALT use (no group):

<?= $updateCase->getImageTag($this->webroot, 'LOCATION', 'ELEMENT', 'false', 'medium'); ?>

And WITH group

<?= $updateCase->getImageTag($this->webroot, 'LOCATION', 'ELEMENT', '1', 'medium'); ?>

If you want to loop through groups and display each image from the groups

<?php $groups = $updateCase->getGroupNamesByLocation("LOCATION"); ?>
<?php if ($groups): foreach ($groups as $group): ?>

<img src="<?= $this->webroot; ?><?= $updateCase->getImage('LOCATION', 'ELEMENT', 'false', 'medium'); ?>" alt="name of pic here"/>

<?php endforeach; endif; ?>


Adding an image to a link:

1 - A normal CakePHP link:

<?= $this->Html->link('Link name', array(
'user' => true,
'controller' => 'CONTROLLER',
'action' => 'ACTION'
), array('class' => 'Classname')); ?>

2 - CakePHP image (Relative to webroot/img OR / to use absolute)

<?= $this->Html->image('v3/map/video-camera.png', array(
'alt' => 'Video available'
)); ?>

3 - To put them together (using image as a link) we need the following

<?= $this->Html->link(
$this->Html->image('v3/map/video-camera.png', array(
'alt' => 'Video available'
)), array(
'user' => true,
'controller' => 'CONTROLLER',
'action' => 'ACTION'
), array('escape' => false, 'class' => 'classNameHere')); ?>


# 7 > Logs

You can view the log if you are having issues figuring which elements / locations you are missing. 

To view the log

simply lookup the website root / updateCase.php

Enter the password

then click 'logs'

# 8 > Show content based on location

Often we need to launch new features on a website / software but we do not want it to display until it has been approved. 
-> UpdateCase features a great way to have your content be visisble only in certain locations - normally NOT visible on the LIVE site. 

The process to setup is simple

if (in_array($_SERVER['HTTP_HOST'], array('livesite.com', 'www.livesite.com'))) {
//what to do when we are LIVE
} else {
//what to do when we are NOT live
$this->set('showAllElements', true);

Then in your VIEW simply place

<?php if (isset($showAllElements)): ?>
Show when NOT live here
<?php endif; //only if not live ?>

# 9 > Highlight links using PHP

When you want to make a link 'ACTIVE' when you are on certain page it is easy to do so:

You simple add a VARIABLE in the controller/action that then displays a 'class' 

So let's say you have a page called 'images' and when you are on that page you want the menu to display it is highlighted

You would add to the controller the following:
NOTE: you can also add the same to other actions i.e. if you have a 'sub page' of IMAGES you might still want to display that it is in the images section so on all the actions (subpages) you would add the same: $this->set('link_images', true);

function images() {
      $this->set('link_images', true);

Now in the view you would add to the 'LI' (NOTICE you can add other styles after the endif meaning they will display all the time and not just when we are on the images page

<li class="<?php if (isset($link_images)): ?>active<?php endif; ?> otherStylesCanGoHere">

Now in your style sheet you would create a style that ensures the links (a) are hightlighted:


li.active a {
background-color: #035e88!important;
color: white!important;

If you create complex links in a heirarchy use underscores to separate the sections. eg if you have a section under 'images' called 'byCategory' you would create the link

$this->set('link_images_byCategory', true);

Then in the VIEW you sould use a organized naming:

<?php if (isset($link_images_byCategory)): ?>active<?php endif; ?> 

Efficiency: There are times when you want a link to display for an entire controller. EG if you have a controller called 'Images' and every action in the controller should display the link in the view as ACTIVE: Then you would simply add your variable to the 'beforeFilter'. The link you add to the specific action will still apply as well. 

function beforeFilter() {
     $this->set('link_images', true);

You can also 'de-activate' a specific link in an action that was applied in the beforeFilter (above). Below the page 'specificAction' the link_images will NOT be active in the view. 

function specificAction() {
     $this->set('link_images', NULL);

# 10 > get Page date

To get the date of the page
-> This assumes you already loaded the page

<?= $updateCase->getPageDate(); ?>
If you want to customize the date format, use PHP date and add as an argument
<?= $updateCase->getPageDate('Y-m-d H:i:s'); ?>


# 11 > By SEARCH term

Allows to search for all pages containing a specific text phrase. 

All the searching is done in the VIEW, so you can pass from the controller to the view the search word

function search() {
$this->set('search', $_GET['data']['Search']);

Then in the View simply do the following

<?php $pages = $updateCase->getPagesBySearch($search); //pr ($tags);exit; ?>
<?php foreach ($pages as $page): ?>

<?= $page['text']; ?>
<?= $page['slug']; ?>
<?= $page['tags']; ?>

<?= $this->Text->highlight(
array('format' => '<span class="highlight">\1</span>')
); ?>

<?php endforeach; ?>



If you only want to get the SLUGS and then call the pages like you normally would you can use

<?php $tags = $updateCase->getPageSlugsBySearch($search); ?>

<?php foreach ($tags as $tag): ?>
<?php $updateCase->loadPageBySlug($tag); ?>
    <?= $updateCase->getContentBy('3-Left', 'status'); ?>

<?php endforeach; ?>

# 12 > Locations

Get all the locations from the current page, so they can be looped through
First specify a page then:

<?php $locationsOnPage = $updateCase->getLocationNames(); ?>
<?php if (locationsOnPage): foreach ($locationsOnPage as $location): ?>

<?= $updateCase->getContentBy($location, 'ELEMENT'); ?>

<?php endforeach; endif; ?>

# 13 > SEO

Simply add the following code to your HEAD tag to popular the SEO

<title><?= $updateCase->getMetaTitle(); ?></title>

<meta name="description" content="<?= $updateCase->getMetaDescription(); ?>">

<meta name="keywords" content="<?= $updateCase->getMetaKeywords(); ?>">


# 14 > Functionality

<?php if ($updateCase->exists('LOCATION','ELEMENT','GROUP is OPTIONAL'): ?>

Anything here will only appear if the above exists

<?php endif; //if exists ?>

If you only want something to appear when it IS empty

<?php if ($updateCase->isEmpty('LOCATION','ELEMENT','GROUP is OPTIONAL'): ?>
Anything here will only appear if the above exists
<?php endif; //if exists ?>


If you DO NOT want something to appear when it is empty/ ONLY show when there is text available

<?php if ($updateCase->isNotEmpty('LOCATION','ELEMENT','GROUP is OPTIONAL'): ?>
Anything here will only appear if the above exists
<?php endif; //if exists ?>



# 15 > By TAG

To get pages by a certain TAG, simple use this call:

<?php $tags = $updateCase->getPageSlugsByTag('TAGNAME', 'ASC|DESC'); ?>
<?php foreach ($tags as $tag): ?>
<?php $updateCase->loadPageBySlug($tag); ?>

//do some stuff here, get contentBy or any other api call here

<?endforeach; //tags ?>

# 16 > By Tag

To get pages by a certain TAG, simple use this call:

<?php $slugs = $updateCase->getPageSlugsByTag('SEARCH TERM'); ?>
<?php foreach ($slugs as $slug): ?>
<?php $updateCase->loadPageBySlug($slug); ?>

//do some stuff here, get content i.e.

<?endforeach; //search ?>

# 17 > Hide Content with PHP

If you want to hide content using PHP you can simple put this:

<?php if (0): ?>

Everything here will not appear even in the html source

<?php endif; //hidden ?>

# 18 > Display content based on a language

You can display separate content based on the language the website is currently set to:

<?php if (isset($langEN)): ?>

//only displayed when ENGLISH is selected

<?php else: //FR ?>

//only displayed when FRENCH is selected

<?php endif; ?>

# 19 > Display content to admin only

You can display separate content based on the language the website is currently set to:

<?php if (isset($isAdmin)): ?>

Put stuff here that only admins will see

<?php endif; ?>

Then in your controller add in a condition so this will only appear when something is true. And that will then display the content in the view above

$this->set('isAdmin', true);


OPPOSITE: You can also only display content when the variable is NOT set: So when you do not add the variable to the controller you will see, when you have the variable the content will NOT display

<?php if (!isset($isAdmin)): ?>

Put stuff here that only admins will see

<?php endif; ?>

# 20 > ConvertString

If you want to change a string:
-> If you have characters which are disrupting a javascript function and you want to quickly change the string

<?= $updateCase->convertString(
$STRING); ?>



<?= $updateCase->convertString(
array("'","\n", "\r", "\n\r","\n\r"), //Searches for the following
array('"',"", "", "",""), //Replaces in order with the above
$updateCase->getContentBy("Right", "text", $group)); ?>

So this means the first element of the Searches array is: ' (quote) and notice the line below it is ", So this means in the entire string all the ' (single quotes) will be replaced with " (double quotes)

# 21 > Update Vimeo link

To Add Vimeo link, 

-> Navigate to Vimeo.com
-> Search for the video you want to add to your site
-> Click share button
-> On the popup window, Copy the link below Link (https://vimeo.com/.....)
-> give a variable name to the link. and follow the steps below 
     (assume your copied link is https://vimeo.com/1122333 )

$video = https://vimeo.com/1122333
$video = str_replace("vimeo.com/", "player.vimeo.com/video/", $video);

-> insert $video within iframe tag











# 22 > Upload file using form

If you want to upload a file using a CAKEPHP form
NOTE: you can change 'Page' to match your model of the page you are in
Action can also be changed to what page you arrive on when you click 'submit'


<?= $this->Form->create('Page', array(
'action' => 'admin_upload/'.$customer_id, 'type' => 'file'
)); ?>
<?= $this->Form->label('Upload File'); ?>
<?= $this->Form->file('File'); ?>
<?= $this->Form->submit('Upload File'); ?>
<?= $this->Form->end(); ?>


# 23 > Add Form tags

<?= $this->Form->input('db_field_name', array(
'label' => 'Visible to the public',
'type' => 'input'
'class' => 'form-control',
)); ?>

Form Checkbox

<?= $this->Form->input('db_field_name', array(
'label' => 'Visible to the public',
'type' => 'checkbox'
'class' => 'form-control',

)); ?>

Form Radio

<?= $this->Form->input('db_field_name', array(
'options' => array(
1 => 'first',
2 => 'second'
'type' => 'radio',
'legend' => 'Public name'
), array(
'class' => 'className'
)); ?>


<?= $this->Form->button('Click here', array(
'onClick' => "window.location='".$this->webroot.$currLang."/Pages/home'",
'class' => 'class name'
)); ?>

Form Dropdown

<?= $this->Form->input('db_field_name', array(
'options' => array(
1 => 'first',
2 => 'second'
'label' => 'Public name'
), array(
'class' => 'className'
)); ?>

# 24 > Jump menu on home screen and dedicated link on sub pages

1 - in Pages Controller -> home, add the following 

$this->set('linkToSamePage', true);

2 -in View -> pages -> home, add the following link



<?php if (isset($linkToSamePage)) {
$url = array('#' => 'subpagename');
} else {
$url = array('action' => 'home', '#' => 'subpagename');
} ?>

<?= $this->Html->link($updateCase->Translate('Domains'), $url); ?>


3 - if linking to the same page, add the following to the section to be linked 

<a name="subpagename">


Q: Why am I getting the error: Helper class updateCaseHelper could not be found.
A1: UpdateCase is NOT a helper this means in your VIEW you are using the syntax '$this->updateCase....' it should actually be '$updateCase.....'
A2: You are trying to load UpdateCase as a helper in the APPController OR YourController: ensure $helpers = array("System.UpdateCase"); DOES NOT exist

Q: I am getting weird errors on the page
A: There are times that errors in your layout will prevent the actual php error from displaying. Create a new layout
titled: blank.ctp 
only add into the file: <?php echo $this->Session->flash(); echo $this->fetch('content'); ?>
then in your app_controller add $this->layout = 'blank';
You will now see the actual error on the page