Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 60 additions & 23 deletions controllers/Matches.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ public function create_app($app = NULL)
}
else
{
$this->create_controller($app);
$this->create_model($app);
$this->create_view($app);
$params = func_get_args();
$this->create_controller(...$params);
$this->create_model(...$params);
$this->create_view(...$params);

}
}
Expand All @@ -194,7 +195,7 @@ public function create_app($app = NULL)
*/
public function create_controller()
{
$available = array('extend'=>'extend','e'=>'extend');
$available = array('extend'=>'extend','e'=>'extend', 'hmvc' => 'hmvc');
$params = func_get_args();
$arguments = array();
foreach($params as $parameter)
Expand All @@ -203,7 +204,7 @@ public function create_controller()
if(sizeof($argument)==1 && !isset($controller))
{
$controller = $argument[0];
}
}
elseif(array_key_exists($argument[0],$available))
{
$arguments[$available[$argument[0]]] = $argument[1];
Expand All @@ -215,7 +216,19 @@ public function create_controller()
$class_name = $names['class'];
$file_name = $names['file'];
$directories = $names['directories'];
if(file_exists(APPPATH.'controllers/'.$file_name.'.php'))

$hmvc = array_key_exists('hmvc',$arguments) ? ($arguments['hmvc'] == 1 ? true : false) : false;
$apppath = $hmvc ? APPPATH.'modules'.$file_name.'/' : APPPATH;
if($hmvc && !file_exists($apppath))
{
mkdir($apppath, 0777, true);
}
if($hmvc && !file_exists($apppath.'controllers/'))
{
mkdir($apppath.'controllers/', 0777, true);
}

if(file_exists($apppath.'controllers/'.$file_name.'.php'))
{
echo $this->_ret.$class_name.' Controller already exists in the application/controllers'.$directories.' directory.';
}
Expand All @@ -230,13 +243,13 @@ public function create_controller()
$extends = in_array(strtolower($extends),array('my','ci')) ? strtoupper($extends) : ucfirst($extends);
$this->_find_replace['{{C_EXTENDS}}'] = $extends;
$f = strtr($f,$this->_find_replace);
if(strlen($directories)>0 && !file_exists(APPPATH.'controllers/'.$directories))
if(strlen($directories)>0 && !file_exists($apppath.'controllers/'.$directories))
{
mkdir(APPPATH.'controllers/'.$directories, 0777, true);
mkdir($apppath.'controllers/'.$directories, 0777, true);
}
if(write_file(APPPATH.'controllers/'.$file_name.'.php',$f))
if(write_file($apppath.'controllers/'.$file_name.'.php',$f))
{
echo $this->_ret.'Controller '.$class_name.' has been created inside '.APPPATH.'controllers/'.$directories.'.';
echo $this->_ret.'Controller '.$class_name.' has been created inside '.$apppath.'controllers/'.$directories.'.';
return TRUE;
}
else
Expand All @@ -257,7 +270,7 @@ public function create_controller()
*/
public function create_model()
{
$available = array('extend'=>'extend','e'=>'extend');
$available = array('extend'=>'extend','e'=>'extend', 'hmvc' => 'hmvc');
$params = func_get_args();
$arguments = array();
foreach($params as $parameter)
Expand All @@ -278,7 +291,19 @@ public function create_model()
$class_name = $names['class'];
$file_name = $names['file'];
$directories = $names['directories'];
if(file_exists(APPPATH.'models/'.$file_name.'.php'))

$hmvc = array_key_exists('hmvc',$arguments) ? ($arguments['hmvc'] == 1 ? true : false) : false;
$apppath = $hmvc ? APPPATH.'modules'.$file_name.'/' : APPPATH;
if($hmvc && !file_exists($apppath))
{
mkdir($apppath, 0777, true);
}
if($hmvc && !file_exists($apppath.'models/'))
{
mkdir($apppath.'models/', 0777, true);
}

if(file_exists($apppath.'models/'.$file_name.'_model.php'))
{
echo $this->_ret.$class_name.' Model already exists in the application/models'.$directories.' directory.';
}
Expand All @@ -287,20 +312,20 @@ public function create_model()
$f = $this->_get_template('model');
if($f === FALSE) return FALSE;
$this->_find_replace['{{MODEL}}'] = $class_name;
$this->_find_replace['{{MODEL_FILE}}'] = $file_name.'.php';
$this->_find_replace['{{MODEL_FILE}}'] = $file_name.'_model.php';

$extends = array_key_exists('extend',$arguments) ? $arguments['extend'] : $this->_mo_extends;
$extends = in_array(strtolower($extends),array('my','ci')) ? strtoupper($extends) : ucfirst($extends);

$this->_find_replace['{{MO_EXTENDS}}'] = $extends;
$f = strtr($f,$this->_find_replace);
if(strlen($directories)>0 && !file_exists(APPPATH.'models/'.$directories))
if(strlen($directories)>0 && !file_exists($apppath.'models/'.$directories))
{
mkdir(APPPATH.'models/'.$directories, 0777, true);
mkdir($apppath.'models/'.$directories, 0777, true);
}
if(write_file(APPPATH.'models/'.$file_name.'.php',$f))
if(write_file($apppath.'models/'.$file_name.'_model.php',$f))
{
echo $this->_ret.'Model '.$class_name.' has been created inside '.APPPATH.'models/'.$directories.'.';
echo $this->_ret.'Model '.$class_name.' has been created inside '.$apppath.'models/'.$directories.'.';
return TRUE;
}
else
Expand All @@ -322,7 +347,7 @@ public function create_model()
*/
public function create_view($view = NULL)
{
$available = array();
$available = array('hmvc' => 'hmvc');
$params = func_get_args();
$arguments = array();
foreach($params as $parameter)
Expand All @@ -342,7 +367,19 @@ public function create_view($view = NULL)
$names = $this->_names($view);
$file_name = strtolower($names['file']);
$directories = $names['directories'];
if(file_exists(APPPATH.'views/'.$file_name.'.php'))

$hmvc = array_key_exists('hmvc',$arguments) ? ($arguments['hmvc'] == 1 ? true : false) : false;
$apppath = $hmvc ? APPPATH.'modules'.$file_name.'/' : APPPATH;
if($hmvc && !file_exists($apppath))
{
mkdir($apppath, 0777, true);
}
if($hmvc && !file_exists($apppath.'views/'))
{
mkdir($apppath.'views/', 0777, true);
}

if(file_exists($apppath.'views/'.$file_name.'.php'))
{
echo $this->_ret.$file_name.' View already exists in the application/views/'.$directories.' directory.';
}
Expand All @@ -352,13 +389,13 @@ public function create_view($view = NULL)
if($f === FALSE) return FALSE;
$this->_find_replace['{{VIEW}}'] = $file_name.'.php';
$f = strtr($f,$this->_find_replace);
if(strlen($directories)>0 && !file_exists(APPPATH.'views/'.$directories))
if(strlen($directories)>0 && !file_exists($apppath.'views/'.$directories))
{
mkdir(APPPATH.'views/'.$directories, 0777, true);
mkdir($apppath.'views/'.$directories, 0777, true);
}
if(write_file(APPPATH.'views/'.$file_name.'.php',$f))
if(write_file($apppath.'views/'.$file_name.'.php',$f))
{
echo $this->_ret.'View '.$file_name.' has been created inside '.APPPATH.'views/'.$directories.'.';
echo $this->_ret.'View '.$file_name.' has been created inside '.$apppath.'views/'.$directories.'.';
return TRUE;
}
else
Expand Down
18 changes: 9 additions & 9 deletions views/matches_templates/controller_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class {{CONTROLLER}} extends {{C_EXTENDS}}_Controller
{
$this->load->model('{{MV}}_model');
$data['content'] = $this->{{MV}}_model->get_all();
$this->load->view('{{MV}}_view', $data);
$this->load->view('{{MV}}', $data);
}

public function get($id)
Expand All @@ -21,7 +21,7 @@ class {{CONTROLLER}} extends {{C_EXTENDS}}_Controller
{
$this->load->model('{{MV}}_model');
$data['content'] = $this->{{MV}}_model->get($id);
$this->load->view('{{MV}}_view', $data);
$this->load->view('{{MV}}', $data);
}
else
{
Expand All @@ -35,19 +35,19 @@ class {{CONTROLLER}} extends {{C_EXTENDS}}_Controller
if($this->form_validation->run()===FALSE)
{
$data['input_element'] = array('name'=>'element', 'id'=>'element', 'value'=>set_value('element'));
$this->load->view('{{MV}}_view', $data);
$this->load->view('{{MV}}', $data);
}
else
{
$field = $this->input->post('element');
$this->load->model('{{MV}}_model');
if($this->{{MV}}_model->add(array('field_name'=>$field)))
{
$this->load->view('{{MV}}_success_page_view');
$this->load->view('{{MV}}_success_page');
}
else
{
$this->load->view('{{MV}}_error_page_view');
$this->load->view('{{MV}}_error_page');
}
}
}
Expand All @@ -68,7 +68,7 @@ class {{CONTROLLER}} extends {{C_EXTENDS}}_Controller
}
$data['input_element'] = array('name'=>'element', 'id'=>'element', 'value'=>set_value('element'));
$data['hidden'] = array('id'=>set_value('id',$id));
$this->load->view('{{MV}}_view', $data);
$this->load->view('{{MV}}', $data);
}
else
{
Expand All @@ -77,11 +77,11 @@ class {{CONTROLLER}} extends {{C_EXTENDS}}_Controller
$this->load->model('{{MV}}_model');
if($this->{{MV}}_model->update(array('element'=>$element),array('id'=>$id)))
{
$this->load->view('{{MV}}_success_page_view', $data);
$this->load->view('{{MV}}_success_page', $data);
}
else
{
$this->load->view('{{MV}}_error_page_view');
$this->load->view('{{MV}}_error_page');
}
}
}
Expand All @@ -92,7 +92,7 @@ class {{CONTROLLER}} extends {{C_EXTENDS}}_Controller
{
$this->load->model('{{MV}}_model');
$data['content'] = $this->{{MV}}_model->delete();
$this->load->view('{{MV}}_view', $data);
$this->load->view('{{MV}}', $data);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions views/matches_templates/model_template.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class {{MODEL}} extends {{MO_EXTENDS}}_Model
class {{MODEL}}_model extends {{MO_EXTENDS}}_Model
{
public function __construct()
{
Expand All @@ -11,5 +11,5 @@ class {{MODEL}} extends {{MO_EXTENDS}}_Model
return ('This is your first application');
}
}
/* End of file '{{MODEL_FILE}}' */
/* End of file '{{MODEL_FILE}}_model' */
/* Location: ./application/models/{{MODEL_FILE}} */