Alpha 4 version Core Changes:
added internal javascript and css manager loader::css, loader::base_css, loader::base_js();,loader::js, loader::script();, loader::base_script();
Changed loader::base_library(); function as base.
added __autoloader to User.php for loading automatically library, model and helper files
changed directory structure , deprecated loader::view(, true) true boolean (fetch as string) and added loader::fetch(), loader::base_fetch(); functions.
added tag builder to User.php ($this->title,$this->head_tag, $this->body_tag)
added active record switch. loader::database(false); functionality
added db_item($key).User can get the db config settings.
added all code igniter helpers.Added session class and session database support.
Added new SSC Class functions.
This is the last alpha version of Obullo framework after that we will release first beta version.I added a lot of internal loader functions that allows to make easy of developers life without adding any external library.
Directory Structure
Controller directory structure changed.We use controllers like modules and current controller has models,helpers,view files which grouped in it’s name.Also /views folder has script and css folders.
The main idea of this framework: Giving the access to users (developers) over the core classes and to prevent long writing.
Don’t forget, Obullo core has MVC-SSC pattern and this pattern use three classes User.php, Loader.php and Ob.php.
User.php : User can control and extend to all controllers with parent:: word and using User.php which located in application/extends/User.php.User can build special SSC functions like this user::nav_level1();.
Ob.php : This is the SSC (super static controller) class.User can control all library functions with small shortcut functions in everywhere except none class functions.(everywhere means Controller, Model, Library ,View and Script files but you can’t use SSC (shortcut functions) in helpers). Forexample you will write just ob::session(‘test’); instead of $this->session->userdata(‘test’); function.Also you can use $this->session->userdata(‘test’); function.
Loader.php: Developer can use advanced loader functions like static.
Using Javascript and css managers that related with User.php:
loader::script(); load script file from /application/controller/views/scripts/ directory.
loader::base_script(); load base script file (like view files) from /base/views/scripts/ directory.
loader:js(); load js file from /application/controller/views/scripts/ directory.
loader::base_js(); load base js file from /base/views/scripts/ directory.
loader::css(); load base css file from /application/controller/views/scripts/ directory.
loader::base_css(); load base css file from /base/views/css/ directory.
We manage
using loader::css and loader::script functions and also we build the html content using User.php.First of all look at the User.php:
<?php
/**
* User.php
*
* o SSC Pattern (c) 2009 Ersin Güvenç
* o Super Static Controllers : User -> Loader -> Ob
*
* Just Put your common special functions here !! "user"
* class works everywhere except helper files. So you
* should put your common functions
* of your application which interested in
* these categories..
*
* o site navigation menu func.,
* o authentication functions
* o module functions
* o and your other special functions that
* you often use them for whole application.
*
* WARNING !: it will work for everywhere like this
* "user::yourfunction()", if your function is a global
* (if every controllers use this function) you should put it
* here, if its not a global function don't put it here
* because of your app performance ..
*
*/
Class UserException extends CommonException{}
// use it like this throw new UserException('error');
Class __autoloader
{
function __construct()
{
// autoload libraries, helpers, lang, config files ..
//loader::base(array('session'));
loader::library(array('navigation'));
loader::helper(array());
loader::base_helper(array('form'));
loader::model(array());
loader::language(array());
loader::config(array());
}
}
Class user extends __autoloader
{
public $base = 'http://localhost/obullo/';
public $base_img = 'base/views/images/';
// Build html content
public $title_tag = '';
public $head_tag = '';
public $body_tag = '';
public $h1 = '';
public $h2 = '';
public $h3 = '';
public $data = array(); // view data
function __user()
{
parent::__construct();
$this->base = $this->config->item('base_url');
$this->base_img = $this->config->item('base_img');
}
function __header()
{
// this is header for every function
$this->data = array(); // data container for view files
$this->title_tag = 'Default common title tag for every page !';
$this->body_tag = 'Default body tag for every page !';
}
// this is parent index() methods for all index() methods...
function __index(){}
public function nav_level1()
{
return $this->navigation->nav_level1().'<br />';
}
public function nav_level2()
{
return $this->navigation->nav_level2().'<br />';
}
} // end class.
?>
In the user.php we have a __autoloader class that is load model, library and helper files like Code Igniter and especially you don’t need set it from config.php.
We have a simple html tag builder and Look at /base/views/vie_base.php file we use it as a base template in the whole application.
<!-- view_base.php --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Lang" content="en"> <meta name="author" content=""> <meta http-equiv="Reply-to" content="@.com"> <meta name="generator" content="PhpED 5.8"> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="creation-date" content="01/01/2009"> <meta name="revisit-after" content="15 days"> <title><?php echo $this->title_tag; ?></title> <?php echo $this->head_tag; ?> </head> <body> <?php echo $this->body_tag; ?> </body> </html>
You can use User class for below the operations
__autoloader functionality
ssc functions (user special common library functions)
parent:: functions if you need
common variables ($this->base, $this->base_img)
and for building the html content easily.
So it makes easier your life. Look at the test contoller and run method.
<?php
Class Test extends Controller
{
public $sample_var = 'you can use $this->variable from view';
public $sample_var2 = 'you can use $this->variable from model';
function __construct()
{
parent::__construct();
// top constructor for every controllers.
parent::__user();
loader::base('session');
loader::helper('dropdowns'); // load helper from /application/ directory
loader::base_helper('form'); // load helper from /base directory
loader::library('mylibrary');
}
function run()
{
parent::__header(); // it runs user class __header() function.
$this->title_tag = 'Im the Test2 Controller !';
echo '<br />Run function succesfully works.<br /><br />';
$data['sample_array'] = array('1','2','3','4','5');
$data['example_var'] = 'Hello World!';
// i can use also $this->data container if i want..
// if you prefer $this way then you don't need $data variable.
$this->data['sample_array2'] = array('6','7','8','9','19');
$this->data['example_var2'] = 'Hello Cruel World!';
$this->body_tag = loader::fetch('view_test',$data);
loader::base_view('view_base');
}
} //end of the class.
?>
and this is the controllers/test/views/view_test.php, we called it before with loader::fetch(); function.
By the way Loader::view(‘filename’, $data, true) function deprecated and instead of we use just loader::fetch(‘filename’,$data) function.
<!-- view_test.php -->
<?php
// load script,js and css files
$this->head_tag.= loader::base_css('example');
$this->head_tag.= loader::base_js('jquery');
$this->head_tag.= loader::script('test');
loader::base_helper('form');
?>
<!-- body_tag start -->
<h3> <?php echo ob::directory(); ?>/views/view_test.php </h3>
<div>
<?php echo "<h1>".$example_var."</h1>"; ?>
<?php echo "<b>Var: </b>".$this->sample_var."<br /><br />"; ?>
<?php foreach($sample_array as $val) { ?>
<?php echo $val."<br />"; ?>
<?php } ?>
<?php echo "<b>this->data['example var2']: </b>" . $example_var2.'<br />'; ?>
<br />
<b>this is loader::script('test'); </b><br />
<?php echo form_button('js_test_button','Alert Me!'," onclick='alertMe();'") ?>
<p></p>
</div>
<!-- body_tag end -->
we build head tags from view file like this…
$this->head_tag.= loader::base_css(‘example’); // this comes from /base folder
$this->head_tag.= loader::base_js(‘jquery’); // this comes from /base folder
$this->head_tag.= loader::script(‘test’);
and the result..
and look at controllers/test/views/scripts/test.php we fetch java script files like view files.
<script language="JavaScript">
<!--
// this is loader::script(); test function
// we will build in <head> </head> tags
function alertMe()
{
alert(' This is the my site base url <?php echo $this->base; ?> ');
return false;
}
//-->
</script>
Using base sesion class with SSC functios.
System SSC functions defined in Ob.php in SSC Class you can look at there which funtions defined for which libraries.
Class SSC extends loader
{
public static function version() { return 'Obullo version 1.0 @alpha 4'; }
//------------- Input Class Shortcut Functions -------------------//
public function xss($str,$is_image = FALSE) { return $this->input->xss_clean($str, $is_image); }
public function post($key = '',$xss_clean = FALSE) { return $this->input->post($key, $xss_clean); }
public function get($key = '',$xss_clean = FALSE) { return $this->input->get($key, $xss_clean); }
public function both($index = '',$xss_clean = FALSE) { return $this->input->get_post($index, $xss_clean); }
public function get_post($index = '',$xss_clean = FALSE) { return $this->input->get_post($index, $xss_clean); }
public function server($index = '',$xss_clean = FALSE) { return $this->input->server($index, $xss_clean); }
public function cookie($index = '',$xss_clean = FALSE) { return $this->input->cookie($index, $xss_clean); }
public function ip() { return $this->input->ip_address(); }
public function valid_ip($ip) { return $this->input->valid_ip($ip); }
public function user_agent(){ return $this->input->user_agent(); }
//------------- Session Class Shortcut Functions -------------------//
public function set_session($newdata = array(),$newval = '') { return $this->session->set_userdata($newdata, $newval); }
public function session($item) { return $this->session->userdata($item); }
public function unset_session($newdata) { return $this->session->unset_userdata($newdata); }
public function set_flash($newdata = array(), $newval = '') { return $this->session->set_flashdata($newdata,$newval); }
public function flash($key) { return $this->session->flashdata($key); }
public function keep_flash($key) { return $this->session->keep_flashdata($key); }
public function sess_destroy() { return $this->session->sess_destroy(); }
public function unset_userdata($newdata = array()) { return $this->session->unset_userdata($newdata); }
//------------- Language Class Shortcut Functions -------------------//
public function lang_load($langfile = '', $idiom = '', $return = FALSE){ return $this->lang->load($langfile, $idiom, $return); }
public function lang($item){ return $this->lang->line($item); }
//------------- Url Helper Shortcut Functions -------------------//
public function base_url() { return $this->config->slash_item('base_url'); }
public function current_url() { return $this->config->site_url($this->uri->uri_string()); }
public function uri_string() { return $this->uri->uri_string(); }
public function index_page() { return $this->config->item('index_page'); }
//-------------- Common.php Already Static Functions ---------------------------//
public function config_item($item) { return config_item($item); }
public function db_item($item, $index = 'default') { return db_item($item, $default); }
} // end ssc class.
Use a SSC session function inside the test_input controller. We use ob::session(); instead of $this->session->userdata(); function.Also you can use $this->session->userdata, it doesn’t matter but i think ssc functions again makes easier your life….
<?php
Class Test_input extends Controller
{
function __construct()
{
parent::__construct();
// top constructor for every controllers.
parent::__user();
loader::base_helper('form');
loader::base('session');
loader::database();
}
function index()
{
$this->title_tag = 'Input and Session Class Test !! ';
loader::base_css('example');
ob::set_session('test','this is a test session variable !');
echo ob::session('test').'<br /><br />';
if(ob::post('username'))
echo '<b>username: </b>' .ob::post('username');
$this->body_tag = form_open('test/test_input');
$this->body_tag.= form_input('username',ob::post('username'));
$this->body_tag.= form_submit('send','Send');
$this->body_tag.= form_close();
loader::base_view('view_base');
}
} //end of the class.
?>
Run the index.php/test/test_input/ controller
and result…



no comments here so far, so let me be the first:
great work, ive been looking for a complete tutorial/showcase on mvc frameworks, and im loving yours so far… im having a hard time catching up haha.
thanks!
Excellent post i often come to your site and read your posts. I am a PHP developer and always try find good posts like this.
Thank you very much