ShiftSmith alpha

ShiftSmith - Docs

Documents in gear

q()

string q()

Get the current URL state. For example: http://mywebsite.com/user, q() would return "/user"

string q( string $string )

Verify if current provided string matches URL path. For example: http://mywebsite.com/user, q('user') would return true. (Shortcut to function inpath)

string q( int $arg )

Get the current URL path. For example: http://mywebsite.com/user, q(0) would return "user".

inpath(string $string)

string inpath('/user/*')

Verify if current provided string matches URL path. For example: http://mywebsite.com/user, inpath("/user/*") would return true.

elog(string $string)

elog('message')

log message in logs/errors.log

form_cache(string $form_name, array $default_values, string $options)

form_cache('my_form', array('first_name'=>'Luc', 'last_name'=>'laverdure))

Steps taken:

  1. If no value is currently set, set default values into session.
  2. Override session variables if POST var or GET var matches a form field

$options:

  1. 'FORCE.CACHE': Force override session values with default values.
  2. 'FETCH.ONLY': POST and GET vars are ignored.

validate_email(string $email)

validate_email('contact@luclaverdure.com')

Returns true if email is valid, returns false if email is invalid.

redirect(string $URL)

redirect('/user')

redirects user to URL specified

t(string $string)

t('user')

print translated output, Database required to host all strings and their matched translations.

email(string $to, string $subject, string $message)

email('contact@luclaverdure.com', 'Hi Luc', 'ShiftSmith is awesome!')

Send email to target $to, with $subject and $message.

Controller

class MyFirstController extends Controller {
	function validate() {
		// when this function returns false,
		// the controller will be destroyed without execution.
		
		// the order of execution will be set by the value returned by this function.
		// 1 being first, 2 being second, [...]
		
		// in the example below,
		// on the page "/user",
		// the controller will fire first.

		// if the user visits any other url,
		// we cancel the execution.
		
		if (inpath('user')) return 1;
		else return false;
		
	}

	function execute() {
		// your application logic goes in this function.
		
		// add models to be passed on to the views
		$this->addModel('page', 'title', 'My First Page Title');
		
		// render a view and give it all controllers models
		$this->loadView('default-theme/home.tpl');
	}
}

Controller->addModel(string $namespace, string $var, string $value)

$this->addModel('page', 'title', 'ShiftSmith')

Add a model to the Controller to render in a view. In the above example, [page.title] would render "ShfitSmith" in a templated file.

Controller->setModel(string $namespace, string $var, string $value)

(deprecated) same as $this->addModel

Controller->modResultsModel(array $results, array $keys, function $function, string $new_col)

???

I forgot what I built this for, usability coming soon!

Controller->getModel(string $namespace, string $var)

$this->getModel('page', 'title')

returns the value of $namespace.$var

Controller->loadModel(string $namespace, string $var, controller $controler)

$this->loadModel('page', 'title')

I forgot what it does o_O

Controller->cacheForm(string $name, array $default_values, Y/N $forcecache)

$this->cacheForm('subscribe', array('email'=>'contact@luclaverdure.com', 'first_name'=>'Luc', 'last_name'=>'the batman'))

Automaticcally save to session all values of the form initial or set

Controller->cacheForm(string $namespace, string $name, string $value)

$this->cacheForm('subscribe', 'email', 'contact@luclaverdure.com')

Single namespace + name cache storage

Controller->getcache(string $namespace, string $name)

$this->getcache('subscribe', 'email')

Single namespace + name cache fetch from storage

Controller->loadView(string||array $view_filename)

$this->loadView('default-theme/docs.tpl')

Render output with models passed to view.

Controller->injectView($selector_output, $mode, $inputURL, $selector_input)

Input: (http://luclaverure.com)


				<html>
					<head></head>
					<body>
						[...]
							<h1 class="name"><a href="/">Luc Laverdure</a></h1>
						[...]
					</body>
				<html>
			

Output: (myapp/view.tpl)


				<html>
					<head></head>
					<body>
						<div class="fetched-title"></div>
					</body>
				<html>
			

Output: (myapp/view.tpl)


				$this->loadView('myapp/view.tpl')
				$this->injectView('.fetched-title', 'append', 'http://luclaverdure.com', 'h1 a');
			

Inject render within view

Controller->loadViewAsJSON($omitted_namespaces, $ommited_models)

$this->loadViewAsJSON(array('user'), array('password'))

Echoes JSON output of all models, except omitted namespaces and omitted models

Controller->loadJSON()

$this->loadJSON()

Echoes JSON output of all models, no exceptions.

Views


<!-- Include header file -->
[header.tpl]

<!-- output model value -->
<h1>[page.title]</h1>

<!-- output translated model value -->
<h2>t[Welcome!]</h2>

<!-- output array block -->
<ul>
[for:myblock]
	<li><a href="[myblock.link]">[myblock.text]</a></li>
[end:myblock]
</ul>

[footer.tpl]