Working with the API

Object types

The main objects in yeager offer a so called "manager" class which may be used to access, add, remove or restructure objects of it's kind. 
 
Objects offering a separated manager class are:
 
Object type Manager class Singleton  Object class
Page PageMgr  sPageMgr($siteId) Page 
Content Block CblockMgr  sCblockMgr() Cblock 
File FileMgr  sFileMgr() File 
Mailing MailingMgr  sMailingMgr() Mailing 
User UserMgr  sUserMgr() User 
 

Objects not offering a separated manager class:
 
Object type Class Singleton   
Comment Comments sComments()  
Entrymask Entrymasks sEntrymasks()  
Filetype Filetypes sFiletypes()  
Site Sites  sSites()  
Tag Tags sTags()  
Template Templates sTemplates()  
Usergroup Usergroups sUsergroups()  
Views Views  sViews()  
 
 
When working with objects we recommend using the singleton instance of the respective manager for performance reasons. If, for any reason, you do not want to use the singleton, please note that you need to prepend a \ in order to break out of your namespace.
 
  1. // instances the PageMgr of the site with the id 1
  2. $pageMgr = new \PageMgr(1);
  3.  
  4. // recommended method using the singleton
  5. $pageMgr = sPageMgr(1);
  6.  
  7. // adding a page at root level
  8. $newPageId = $pageMgr->add(1);
  9.  
  10. // getting an instance of the respective page
  11. $page = $pageMgr->getPage($newPageId);
  12.  
  13. // doing stuff with the page
  14. $page->setTemplateByIdentifier('homepage');
  15. $page->setPName('home');
  16. $page->properties->setValue('NAME','Homepage');
  17. $url = $page->getUrl();

Accessing content

Accessing an object's content is probably the most common use case. You can do that via: 
  1. // callback function exectued when an object this extension is assgined to gets published
  2. public function onPublish ($args = NULL) {
  3.     // get the page which just got published
  4.     $page = $this->getPage();
  5.  
  6.     // get the content
  7.     $content = $page->getContent();
  8. }

Accessing properties

Accessing an object's or an Extension's properties is described in the Properties section.

Assigning variables to Smarty

You can assign variables to Smarty making use of it's Singleton.
  1. sSmarty->assign("xyz", "value");
And in the template you can access it via:
  1. {$xyz}

Requests

sApp->request holds all relevant information about the request.
  1. // accessing POST and GET parameters
  2. $parameter = sApp()->request->parameters["parametername"];
  3.  
  4. // http or https?
  5. $prefix = sApp()->request->prefix;
  6.  
  7. // host
  8. $host = sApp()->request->http_host;
  9.  
  10. // host name
  11. $hostname = sApp()->request->http_hostname;
  12.  
  13. // ip address
  14. $ip = sApp()->request->client_ip;

Config variables

Accessing any of the configured settings in the config.xml files works as follows:
  1. sConfig()->getVar("CONFIG/PATH/TO/SETTING/IN/XML");
  2.  
  3. // get configured TMP path
  4. sConfig()->getVar("CONFIG/PATH/TMP");
  5.  
  6. // accessing attributes
  7. $databaseInfo = sConfig()->getVars('CONFIG/DB');
  8. $databaseHost = $databaseInfo[0]['host'];

Sessions

You can use yeager's session handling to authenticate users or save data in the session.
  1. // writing data to the session
  2. sApp()->session->setPSessionVar('customvar', 'custom value');
  3.  
  4. // reading data from the session
  5. $variable = $this->session->getSessionVar('customvar');
  6.  
  7. // authenticate after checking a users access data
  8. sApp()->session->setPSessionVar('username', $userName);
  9. sApp()->session->setPSessionVar('password', $userPassword);
  10. sApp()->session->setPSessionVar('isvalidated', true);  
  11.  
  12. // logout
  13. sApp()->session->setPSessionVar('username', sApp()->_login);
  14. sApp()->session->setPSessionVar('password', '');
  15. sApp()->session->setPSessionVar('isvalidated', false);