\Ceo\Core\ManagersSettingManager

Setting manager assists in setting and retrieving values.

Since settings are stored with type information in a base64 encoded string you can decode them yourself via the Setting model. This just assists with that.

Summary

Methods
Properties
Constants
save()
getPaginator()
restDelete()
restCreate()
restUpdate()
findFirstById()
findFirst()
find()
allLabels()
set()
get()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
encodeValue()
decodeValue()
No private properties found
N/A

Methods

save()

save(object  $obj) : object

Save handler, because DRY

Parameters

object $obj

Model to be saved

Throws

\Ceo\Core\Managers\Exception

Json encoded string of validation errors

Returns

object —

Model

getPaginator()

getPaginator(integer  $page = 1, integer  $limit = 50) : \Ceo\Core\Managers\Ceo\Core\ModelHelpers\Paginator

Helps paginate models using the query bulder. Bit more complicated than the native array method, but works better for larger data sets

Because it's based on Phalcon's QueryBuilder, it supports a fluent filtering interface:

    $manager = $this->foo_manager;
    $items = $manager->getPaginator(1, 20)
        ->orderBy('created_at desc')
        ->where('name = :name:', array('name' => $name))
        ->andWhere('type = :type:', array('type' => $type))
        ->paginate();

    echo json_encode($items);

Parameters

integer $page

Current page

integer $limit

Per page limit

Returns

\Ceo\Core\Managers\Ceo\Core\ModelHelpers\Paginator

restDelete()

restDelete(\Ceo\Core\Managers\number  $id) : boolean

Delete an object with rest

Parameters

\Ceo\Core\Managers\number $id

Throws

\Exception

Returns

boolean

restCreate()

restCreate(array  $data) 

Create a new object

Parameters

array $data

restUpdate()

restUpdate(integer  $id, array  $data) 

Update an existing object

Parameters

integer $id
array $data

findFirstById()

findFirstById(  $params = null) 

Parameters

$params

findFirst()

findFirst(  $params = null) 

Parameters

$params

find()

find(  $params = null) 

Parameters

$params

allLabels()

allLabels() : array

Return a list of all keys

Returns

array —

of strings

set()

set(string  $k, mixed  $v, boolean  $abortIfExists = false) : mixed

Set setting value.

$manager->set('some-value', ['foo' => 'bar']);

Parameters

string $k

Setting label

mixed $v

Setting value

boolean $abortIfExists

If TRUE, will not reset an existing value

Throws

\Exception

if unable to encode value

Returns

mixed —

The original value

get()

get(string  $k, mixed  $default = false) : mixed

Retrieve a setting value. Returns the default value if not found.

Keep in mind that the settings manager is type aware, so values will be returned as a scalar, array or object. For example: $manager->set('some-key', true); $manager->get('some-key'); // Will be scalar TRUE

Similarly, if you pass a string number, it will be converted to a scalar float or int: $manager->set('some-key', '3.14159'); echo $manager->get('some-key') === '3.14159' ? 'Equal' : 'Not equal'; // Not equal echo $manager->get('some-key') === 3.14159 ? 'Equal' : 'Not equal'; // Equal

Parameters

string $k

Setting key

mixed $default

Default value to return

Throws

\Exception

if unable to decode value

Returns

mixed

encodeValue()

encodeValue(mixed  $v) 

Encode value as scalar, array or object

Parameters

mixed $v

decodeValue()

decodeValue(string  $v) : mixed

Decode serialized value

Parameters

string $v

Returns

mixed