\lfcms

# cms class

The cms class is used primarily to execute apps assigned to navigation items that are browsed by their alias (eg, '/blog' has the blog app assigned to it, so when the page loads, the linked app will return its resulting output and then render it the assigned theme). All the operations used to perform this are public.

this is the main class (formerly class littlefoot) that handles all the aspects of the higher level CMS operations such as lf_actions navigation selection from request_uri (formerly littlefoot->navSelect()), app loading from lf_links, skin rendering, acl testing (should really be its own class). \lf\Cms

LEGACY APP DOX

  • A base class definition meant to be extended in littlefoot apps

How to App

When you extend app brings a lot of helpful tools into your environment. Here is a list of what is accessible when developing a littlefoot app. All that follows is accessible in the app's index.php as well.

$this->

There are several objects available in your environment:

  • $this->lf: Littlefoot instance
    • ->appurl (rendering of %appurl% without waiting for $lf->render(). Ideal for use with redirect302(); )
    • ->baseurl (%baseurl%)
    • ->relbase (%relbase%)
  • $this->db: Database instance
  • $this->auth: Auth instance

Static

Classes meant to be called statically:

  • orm::q('table_name')
  • dba::Table_name

init()

If you need something to run before all functions, you can do it in an 'init()' function. This function is automatically called from __construct() just before any other controller is executed.

$args

Given domain.com/myapp/view/5

$this->lf->action = array('myapp');
$this->lf->vars = array('view', '5');

Littlefoot serves requests based on the URL. For example, if we ask for "domain.com/blog", it knows to serve "/blog". The "/blog" navigation item has been associated with the "Blog" app in the admin backend. So we wind up being presented with Blog. Simple enough right? Now lets get to $args.

The Blog navigation item has been set as an "app". This means that any extra part of the URL past the matching "/blog" request is taken as variables for the "Blog" app rather than a separate navigation item. Alternatively, if it was not set as an "app", we could make child navigation items and serve them without conflict.

If we ask for "domain.com/blog/view/5", the "view/5" is taken as a variable for the Blog app. The Blog app utilizes a Model-View-Controller structure and uses its class methods as a kind of router. The variable taken from the url is split on the "/" to give us an array of "(view, 5)". The first part, "view", is used to determine which method of Blog to serve. In this case, it will use the view() method and since the "5" is specified, the Blog is programmed to serve the Blog post with an "id" of 5.

MVC

The URI is chopped up into arguments and those arguments route the controller.

URI routing to controller class methods

Create a file at ROOT/apps/myapp/index.php that contains

<?php echo $this->lf->mvc('myapp');

Then at ROOT/apps/myapp/controller/myapp.php, create a file with the following code:

<?php

class myapp {
    public function main() {
        echo '<a href="%appurl%otherfunction/1">otherfunction</a>';
        }

    public function otherfunction() {
        echo '<a href="%appurl%">back to main</a>';
        }
}

If you go into the Dashboard and assign this app to the navigation, a link will appear on the navigation. When you click it, the screen will display the content of $args

I strongly recommend reviewing the code of the Pages app. It is an excellent example of the intended use of mvc()

With the above app assigned in nav at /theapp/, the above renders as follows:

<a href="http://domain.com/theapp/otherfunction">otherfunction</a>

If you click this link, the app will render as follows:

<a href="http://domain.com/theapp/">main</a>
<pre>
array(0 => 'otherfunction', 1 => '1')
</pre>

And links back to the main function. Follow the [Littlefoot app tutorial]() for a more in-depth guide.

Variable Scope

If you need a value to be accessible throughout an app (including within a partial) without needing to pass by value or reference, you can simply set the variable as such:

$this->mySpecialVar = 'some value I want to use everywhere, or just for this part'; $this->myOtherSpecialVar = array('something' => 'cool');

And these will be accessible everywhere in the app (helpful for recursive partials)

Partials

$this->partial('some-partial', array('myvar' => 'someval');

<?php // view/some-partial.php

echo $myvar; // "someval"

Summary

Methods
Properties
Constants
run()
printDebug()
loadLfCss()
loadVersion()
getVersion()
simpleCms()
routeAdmin()
loadSettings()
getSettings()
getSetting()
mvc()
multiMVC()
router()
route()
getNavCache()
renderNavCache()
renderBaseUrl()
getApps()
homeTest()
setSiteTitle()
searchEngineBlocker()
simpleSelect()
actionFromCache()
navSelect()
setTemplateSkin()
getSortedActions()
getHiddenActions()
getLinks()
getcontent()
partial()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$exec
$instances
$ini
$version
N/A

Properties

$exec

$exec : 

Type

$instances

$instances : 

Type

$ini

$ini : 

Type

$version

$version : 

Type

Methods

run()

run() : $this

Originally `(new littlefoot)->cms()`

Executes the Littlefoot CMS frontend (loading /admin, if requested)

Returns

$this —

The resulting $this object

printDebug()

printDebug() 

print HTML comment at the bottom of the source

display cool stats and list of required files

loadLfCss()

loadLfCss() 

use template to add lfcss and icon css to top of <head> on render

loadVersion()

loadVersion() 

load release version. used mostly for upgrade at the moment. may add to debug output

getVersion()

getVersion() 

return string of loaded lf release version

simpleCms()

simpleCms(  $app) 

enable SimpleCMS for $app. It will treat $app as alias `/` and as if no other nav items exist

UI: admin navigation page is replaced with $app admin. other apps are hidden. full site navigation cannot be modified while this is on.

Parameters

$app

routeAdmin()

routeAdmin() 

If user asks for 'admin/' in their request_uri, run admin

loadSettings()

loadSettings() 

load CMS settings into session from `lf_settings`

getSettings()

getSettings() 

Return all loaded settings in an array

getSetting()

getSetting(  $name) 

Return loaded CMS setting called $name

Parameters

$name

mvc()

mvc(string  $controller, string  $ini = '',   $param = NULL) 

Instant MVC: Routing URL request to class methods.

request param is used to route to class methods.

Given class pages_admin and param = ['edit', '5'], mvc would execute the edit() method and that method would know to ask request for param[1]

Usage

include "controller/$controllerName.php";
echo (new \lf\cms)->mvc( (new $controllerName) );

Parameters

string $controller

Executes $controller->$vars[0]() defined at ./controller/$controller.php

string $ini

= '' (by default) App configuration set Dashboard. Used in 'Pages' app to select the page to display on the website.

$param

multiMVC()

multiMVC(  $default = NULL,   $section = 'content',   $namespace = '\\') 

Routes `action[0]` to local files at `controller/$action[0].php` to let a folder of controller names handle the request action rather than `navSelect()`

Runs (new \lf\cms)->mvc( (new $action[0]) ); after including the file found above.

Parameters

$default
$section
$namespace

router()

router(array  $args, string  $default_route = 'home', array  $filter = array()) : string

I haven't used this recently and will update the docs if I run into it again.

used to route based on args[0] as instance

How to use _router

Dynamically route controller based on a common URI base

ie, /_auth/mymethod, /_auth/myothermethod

$auth = new auth($this, $this->db);

// change to auth class
if($this->action[0] == '_auth' && isset($this->action[1]))
{
        $out = $auth->_router($this->action);
        $out = str_replace('%appurl%', $this->base.'_auth/', $out);
        $content['%content%'][] = $out;

        // display in skin
        echo $this->render($content);

        exit(); // end auth session after render,
        // otherwise it will 302 (login/logout)
}

Parameters

array $args

URL Variables.

string $default_route

Default function for router when none is specified. Uses function "home" by default.

array $filter

If set, limit valid functions to those in the array; eg, array('func2', 'func3')

Routing URL based on /subdir/action1/param1/method1/param2 I moved this from app, but dont plan on actually fixing it until I need it again. I think when I wrote this, I was doing something studid and had to work around it.

Returns

string —

Captured output buffer from execution of $this->$method()

route()

route(  $instance,   $alias = NULL,   $return = true) 

Test URL for given alias (default to given class) in action[0]

Parameters

$instance
$alias

Defaults to $class. This only routes if we find $alias in getRequest('Action')[0].

$return

bool "The output of this should be returned as a captured string rather than immediately rendering and exiting".

getNavCache()

getNavCache() 

renderNavCache()

renderNavCache() 

renderBaseUrl()

renderBaseUrl(  $text) 

Parameters

$text

getApps()

getApps(  $id = NULL) 

Parameters

$id

homeTest()

homeTest() 

setSiteTitle()

setSiteTitle() 

searchEngineBlocker()

searchEngineBlocker() 

simpleSelect()

simpleSelect(  $app = NULL) 

Parameters

$app

actionFromCache()

actionFromCache(  $action = null) 

Parameters

$action

navSelect()

navSelect() 

# navSelect

Determine which navigation item was requested based on wwwAction and navigation hierarchy.

Results with $this->select containing the lf_actions row data of the matching navigation item.

setTemplateSkin()

setTemplateSkin() 

getSortedActions()

getSortedActions() 

getHiddenActions()

getHiddenActions() 

getLinks()

getLinks() 

getcontent()

getcontent() 

partial()

partial(  $partial, array  $args = array()) 

Used for loading partial views given an argument

Parameters

$partial
array $args

Associative array of $var => $val passed to the partial.