| Source Code Access Required | No |
| Skills Required | PHP, XML, HTTP |
There are many reasons that you may want to stick with standard (centralized) code. You may want the updates as soon as they arrive, or you may simply wish to tinker without worrying about code mergers. You can indeed still write PHP code for your social network while staying on the standard code.
This tutorial builds on the Advanced Member Search tutorial. It describes how to shoe-horn this functionality into a social network running the standard code. This same technique should work for many features in other tutorials, but it will not work for all of them. Some features are simply not available unless your feature is implemented as part of the Ning Web Widget Framework. Furthermore, this technique involves cramming all of the templates and models into a single PHP file. This means it will obviously quickly become a nightmare for more complex features.
I strongly recommend that you run through the Advanced Member Search tutorial before attempting this tutorial.
To get started on this tutorial we'll need to create a PHP file in which to implement this feature. We'll also need to import a few libraries in order to access functions provided by the social network.
memberSearch.php in the root directory of your social network. This is where we'll be pasting and hacking our code.<?php
//include some stuff that we need
define('NF_APP_BASE',$_SERVER['DOCUMENT_ROOT']);
require 'WWF/bot.php';
require NF_APP_BASE . '/lib/XG_App.php';
require_once NF_APP_BASE . '/lib/XG_Query.php';
call_user_func(array(W_Cache::getClass('app'),'loadWidgets'));
$user = User::loadOrCreate(XN_Profile::current());
For the next phase we'll need to copy in the contents of the controller. In this case we have only one controller so it'll be pretty easy, but if multiple controllers exist on the feature that you're attempting to implement you may have to get creative with some switching code.
/widgets/memberSearch/controllers/IndexController.php.extends W_Controller from the class declaration.//create a new instance of this class
$page = new MemberSearch_IndexController();
$page->action_index();
render() function is no longer accessible to us. We need to hack our own implementation. Luckily we only make two calls so this will be an easy replacement. Near line 92 replace $this->render("searchResults"); with $this->renderSearchResults(); and $this->render("searchForm"); with $this->renderSearchForm();.We're almost there! Next we simply have to create those render methods we called in the last step. We'll implement these as class functions and paste in the template contents.
public function renderSearchForm() and paste the contents of the /widgets/memberSearch/templates/index/searchForm.php file into this function. You may need to clean up extraneous begin and end PHP tags./widgets/memberSearch/templates/index/searchResults.php
xg_sidebar($this);. You should find one in each template method. Comment both of them out.So now you have a member search that you can access directly. What if you want to add a tab to access it? No problem. You can use the JavaScript technique outlined here.
This development technique is far from graceful and has many limitations. Be sure to test your feature our throughly as it's hard to predict what will not work when implemented this way. Once your testing is complete enjoy your feature while still receiving automatic updates!
Lastly, if you ran into a hitch or just don't want to bother going through this tutorial, click here to download a copy of the final code that results from this tutorial in a zip file.
Last updated by Ning Developer Admin May 9.
© 2008 Created by Ning Developer Admin