tailieunhanh - Tạo mạng xã hội với PHP - part 39
Developing an API $registry-getObject('template')-getPage()-addTag( 'siteurl', $registry-getSetting('siteurl') ); $registry-getObject('template')buildFromTemplates('', '', ''); $controllers = array(); $controllersSQL = "SELECT * FROM controllers WHERE active=1"; $registry-getObject('db')-executeQuery( $controllersSQL ); Next, we need to change the code that gets active controllers from the database. Previously, it set the $controller variable for temporary use. This wasn't a problem initially, because we reset the variable to the active controller after this. However, now it is overriding our default controller. This is simply altered by changing $controller to $cttrlr. while( $cttrlr = $registry-getObject('db')-getRows() ) { $controllers[] = $cttrlr['controller']; } The final change is to only add authentication-related template bits to the view,. | Developing an API registry- getObject template - getPage - addTag siteurl registry- getSetting siteurl registry- getObject template - buildFromTemplates controllers array controllersSQL SELECT FROM controllers WHERE active 1 registry- getObject db - executeQuery controllersSQL Next we need to change the code that gets active controllers from the database. Previously it set the controller variable for temporary use. This wasn t a problem initially because we reset the variable to the active controller after this. However now it is overriding our default controller. This is simply altered by changing controller to cttrlr. while cttrlr registry- getObject db - getRows controllers cttrlr controller The final change is to only add authentication-related template bits to the view if the active controller isn t API. if registry- getObject authenticate - isLoggedIn controller api registry- getObject template - addTemplateBit userbar registry- getObject template - getPage - addTag username registry- getObject authenticate - getUser - getUsername elseif controller api registry- getObject template - addTemplateBit userbar if in_array controller controllers require_once FRAMEWORK_PATH . controllers . controller . controllerInc controller. controller controller new controllerInc registry true else ----------------------------------- 362 ----------------------------------- Download from Chapter 11 default controller or pass control to CMS type system registry- getObject template - parseOutput print registry- getObject template - getPage - getContentToPrint Delegating control API controllers for our features With the basic API controller in place we can now add delegate controllers for the features on our site. As discussed earlier in this chapter we will only look at adding support for profiles however it is easy to extend should you wish to. Profile s delegate Our
đang nạp các trang xem trước