Skip to content
Alan Smith edited this page Jul 5, 2011 · 2 revisions

Acorn

This is the class you'll be using the most. You don't need to know much about the other classes except <AN_Model>.

See

AN_Model

defineModel

Alias for AN_Model::defineModel

See

AN_Model::defineModel

database

Returns database connection using the specified settings. Required keys are: user, password, database, host, adapter.

<?php Acorn::database(array('user' => 'skrat', 'password' => 'nut', 'database' => 'acorn_tree', 'host' => 'localhost', 'adapter' => 'mysql')) ?>

Return

{AN_Database}

Database connection.

See

AN_Database

error

Sets status and displays error.

Parameters

code int Error code

load

Loads named file with the given type.

<?php Acorn::load('model', 'User'); ?>

Parameters

type String Type of file.
name String - Name of file.

Return

{bool}

True if successfully loaded file.

See

filePath

filePath

Searches Acorn::$include_paths for the specified file.

<?php $path = Acorn::filePath('model', 'User'); ?>

Parameters

type String Type of file - it gets converted to lowercase (e.g. 'model').
name String Name of file - it gets converted to lowercase (e.g. 'User').

Return

{bool | String}

False if no file exists, otherwise path of file.

renderView

Renders the view at the specified path.

<?php Acorn::renderView('./users/info'); ?>

Parameters

file String Path to the view file.
layout String Name of the layout to render the view in. If null no layout will be used. (Default: layout)

See

filePath

renderPartial

Renders a partial with the specified name and returns it as a string.

Parameters

name String Name of the partial to render (e.g. 'posts/detail' would be 'posts/_detail.php' on disk).
var Mixed Variable to be given the name of the partial (e.g. name = 'posts/detail', $detail = $var).
extra_vars Array Variables for the partial to use. (e.g. array('user' => $user, 'time' => time()))

Return

{String}

Contents of the rendered partial.

route

Connects a URL to a callback with default parameters and regular expression requirements.

<?php
Acorn::route('GET /posts/:id', 'viewPost', null, array('id' => '\d+'));
Acorn::route('GET /pages/:name', 'viewPage', array('name' => 'home'));
?>

Parameters

url String The URL to match.
callback Mixed The callback to be used when this route is matched.
defaults Array The default paramenters to be passed to the callback.
regex Array Regular expressions to define the segments in the URL.

url

Converts the given parameters into a URL appropriate for a link.

<?php echo Acorn::url(array('action' => 'view', 'id' => 1)); ?>

Parameters

params Array Array of key/value pairs to match to a route.
method String Request method that matches the method at the beginning of the route.

Return

{String}

The URL as a string if a route is found. Null if no match is made.

run

Calls the first matched route for $url. If no parameters are passed the current request method and request uri are used.

Parameters

url String The URL to route. Must have a request method at the beginning (e.g. "GET /").

underscore

Converts string to lowercase and replaces lowercase letter followed by a uppercase letter with the lowercase version of both separated by an underscore.

Parameters

str String String to underscore.

Return

{String}

Underscored version of string.

Clone this wiki locally