Back to Littlefoot Manual

How to App

A base class definition meant to be extended in littlefoot apps

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.


There are several objects available in your environment:


Classes meant to be called statically:

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


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.



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

Littlefoot serves requests based on the URL. For example, if we ask for "", 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 "", 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.


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:


class myapp extends app {
        function main($args) {
            echo '<a href="">otherfunction</a>';
            //echo '<pre>';
            //var_dump($args, $this);
            //echo '</pre>';

        function otherfunction($args) {
            echo '<a href="">back to main</a>';
            echo '<pre>';
            echo '</pre>';

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="">otherfunction</a>

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

<a href="">main</a>
array(0 => 'otherfunction', 1 => '1')

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)


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

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

echo $myvar; // "someval"
blog comments powered by Disqus