Chapter 8. Selectors

Selectors are a unique feature of Atomik! They are inspired from Javascript frameworks which uses CSS selectors to select object in the DOM.

Atomik Selectors allow you to select any kind of data or object.

You've already encountered selectors when you discovered accessors. Selectors are available through the Atomik::get() method.

Atomik also defines the A() function for quicker access. This function is only a shortcut to Atomik::get().

Namespaces are used to differentiate selectors. A namespace is only a word followed by “:” at the beggining of the selector.

The only built-in selector (and the only one which doesn't need any namespace) gives the availability to query through arrays. It has alreay been covered in the Accessors and configuration section.

Example 8.1. Using the built-in selector

// setting value in the global store
	'key1' => array(
		'key2' => 'value'

// selecting a value from the global store
$value = A('key1/key2');

Plugins can provide their own selector namespace. For example, the Db plugin brings with it the “db” namespace which allow you to do sql queries.

Example 8.2. Using the selector provided by the Db plugin

// selecting a value from the global store
$value = A('key1/key2/key3');

// selecting all posts
$allPosts = A('db:SELECT * FROM posts');

// selecting the first post
$firstPost = A('db:SELECT * FROM posts WHERE id = ?', array(1));

See the Db plugin documentation for more information.