[eluser]Joozt[/eluser]
I am fairly new to the CondeIgniter framework.
If i read things right then it isn't possible to call a function of an other controllers in a controller. So if i have a class with functions that I want to use in Controllers where do I place it? Should I use it as model? helper? or what
Example:
Say I have a class called Lock witch checks if content is locked or not (in use by an other user.
Code:
class Lock extends ?????
{
/**
* Class initialization
*/
public function Lock()
{
parent::__construct();
# Load path settings file
$this->load->config('application', true);
$this->unvalidated_dir = $this->config->item('unvalidated_dir','application');
$this->archived_dir = $this->config->item('archived_dir','application');
$this->converted_dir = $this->config->item('converted_dir','application');
$this->archived_dir = $this->config->item('archived_dir','application');
$this->thumb_dir = $this->config->item('thumb_dir','application');
$this->usable_dir = $this->config->item('usable_dir','application');
$this->unvalidated_dir = $this->config->item('unvalidated_dir','application');
}
function index()
{
Lock::setLock("get_new.xml");
}
function checkLock($filename){
$currenttime=time();
$xmlData = file_get_contents($this->archived_dir.$filename);
$domDoc = new DOMDocument ();
$domDoc->preserveWhiteSpace = false;
if ($domDoc->loadXML ($xmlData))
{
//Set lock value of XML to 1
$nodeItems = $domDoc->getElementsByTagName("locked");
foreach ($nodeItems as $nodeItem)
{
$lock=$nodeItem->nodeValue;
}
//END
//Set lock_timestamp value to current time
$nodeItems = $domDoc->getElementsByTagName("locked_timestamp");
foreach ($nodeItems as $nodeItem)
{
$lockTime=$nodeItem->nodeValue;
}
//END
}
//ADD 20 min to the locktime
//Check if a file is locked
if($lock!=1){
return false;
}else{
//ADD 20 min to the locktime
$lockTime=$lockTime+(20*60);
if($currenttime>$lockTime){
return false;
}else{
return true;
}
}
}
Now I have an other Controller class Content
Code:
<?php
class Content extends Controller {
function Content(){
parent::Controller();
}
function index(){
if(Lock::checkLock){
$this->load->view('content', $page);
}
}
}
?>
So I want to use my Lock class in other controllers, but what is the best place to place this Class.
I am programming object oriented and want to keep things clean.
Thanks in advance