Skip to content

Instantly share code, notes, and snippets.

@jmas
Last active December 31, 2015 04:59
Show Gist options
  • Save jmas/7937773 to your computer and use it in GitHub Desktop.
Save jmas/7937773 to your computer and use it in GitHub Desktop.
Uri
__construct()
this.parse()
parse()
Logger
register()
exceptionHandler()
errorHandler()
Request
getParam(key, [defaultValue])
return _REQUEST[key]
getQuery(key)
return _GET[key]
getPost(key, [defaultValue])
return _POST[key]
getFiles(key)
return _FILES[key]
Observer
callbacks
observe(name, callbackFn)
notify(name, [args])
Db extends PDO
__construct([config])
parent.__construct()
connection
Model
attrs
db
__construct()
this.db = Flexio.get('Db')
getAttr(key, [defaultValue])
setAttr(key, value)
getAttrs(attrs)
setAttrs(attra)
validate()
save()
delete()
Flexio
config
page
getConfig(key, [defaultValue])
get(className)
end()
Observer.notify('systemEnd')
exit
run()
Log.register()
Observer.notify('systemRun')
path = Request.getQuery('path')
Observer.notify('currentPageBeforeFind', array(path))
this.page = Page.find(path)
if (this.page === null)
Observer.notify('currentPageAfterFind', array(this.page, path))
view = Page.getView()
view.setValues({ page: this.page })
Observer.notify('currentPageBeforeRender', array(this.page, view))
view.render()
Observer.notify('currentPageAfterRender', array(this.page))
else
Observer.notify('currentPageNotFound')
throw new Exception('Page not found')
this.end()
currentPage()
return this.page
currentUrl()
return this.baseUrl() . Request.getQuery('path')
baseUrl()
scriptName = _SERVER['SCRIPT_NAME']
return _SERVER['SERVER_NAME'] . substr(scriptName, 0, strrpos(scriptName, '/'))
Page ext Model
attrs
id
name
title
createDate
updateDate
publishDate
parentId
viewId
contentType
slug
path
__construct([attrs])
this.setAttrs(attrs)
findAll([opts = { [where] [params] [limit] [offset] }])
Observer::notify('pageBeforeFind', array(opts))
Observer::notify('pageAfterFind', array(this))
find(id)
this.findAll()
find(where)
this.findAll()
findByPath(path)
this.findAll()
root()
this.findAll()
children()
parent()
return this.find(this.parentId)
next()
return this.find()
prev()
return this.find()
delete()
save()
isNew()
isPublished()
isCurrent()
return this.id === Flexio.currentPage().id
path()
url()
link()
breadcrumbs()
getView()
getAttr(key, [defaultValue])
return this.getAttrs()[key]
setAttr(key, value)
attrs = this.getAttrs()
attrs[key] = value;
return this.setAttrs(attrs)
getAttrs()
return this.attrs
setAttrs(attrs)
Observer.notify('pageGetAttrs', array(this))
this.attrs = attrs
PageContent ext Model
attrs
id
name
pageId
content
createDate
updateDate
findAll()
find()
delete()
save()
toString()
return this.getAttr('content')
View ext Model
attrs
id
name
content
createDate
updateDate
__construct([id])
this.find(id)
find(id)
find(name)
setValues(values)
setValue(name, value)
render([isNeedReturn])
delete()
save()
Plugin ext Model
attrs
id
name
git
version
isActive
isUpdate
createDate
updateDate
config
__construct([attrs])
parent.__construct([attrs])
if (this.init)
this.init()
find(id)
findAll([{ [where] [params] [limit] [offset] }])
getConfig(key, [defaultValue])
setConfig(key, value)
User ext Model
attrs
id
name
email
password
createDate
updateDate
find(id)
findAll([{ [where] [params] [limit] [offset] }])
delete()
save()
PageImagePlugin ext Plugin
init()
echo 'PageImagePlugin initialized'
onPageAfterSave(page)
foreach (page.images as image) {
image.save()
}
onPageAfterFind(page)
page.images = PageImage.findAll({
pageId: page.id
})
# Page examples
Page.findByPath('/catalog').children()
Page.root().children()
Page.getView().render()
page = new Page({
name: 'My page',
title: 'Some Page',
slug: 'someSlug',
parentId: 1
})
page.save()
page.id
# Observer example
Observer.observe('currentPageBeforeRender', function(page, view) {
uri = new Uri(Flexio.currentUrl())
if (uri.getExt() === 'json') {
echo json_encode(page.getAttrs())
Flexio.end()
}
});
Observer.observe('pageAfterFind', function(page) {
page.images = PageImage.findAll({
pageId: page.id
})
})
Observer.observe('pageAfterSave', function(page) {
foreach (page.images as image) {
image.save()
}
})
Observer.observe('pageAfterFind', function(page) {
page.content = PageContent.findAll({
pageId: page.id
})
})
echo Page.root().content['name']
# Other examples
Flexio.currentPage().parent().title
Flexio.getConfig('db')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment