Skip to content

Commit

Permalink
Add stripTags option to model.
Browse files Browse the repository at this point in the history
Add magic method __set in model to implement strip_tags.
Add `postList` function to controller template.
Add `parent::__construct` to Ertikazos_Seeder class.
Add `make_label` in `make_search_form` function.
Add `hidden-print` CSS and print only the page content.
Add `@media print` to styles.
Add ER_VERSION in footer.

Rewrite `forms` and `rules` methods in model.
Use forms function instead of forms array in all models.
Fix CI_numeric in validation.js
Update .gitignore to ignore uploads folder.
Fix form_validation if rules array is empty.
Fix replacing class_name and app_name in language files.
Fix replacing class_name and app_name in view_list by using str_replace.
Change make_search_form to accept input array as first parameter.
Use short array syntax in most of files.
Use empty instead of isset in make_input helper.
Change Admin application icons.
Fix script tag by adding type="text/javascript"

Remove `$this->rules` array from all models.
Remove useless `$this->permission` from Group_model class.
Remove bootstrap.css.map line from bootstrap.css
  • Loading branch information
daif committed Apr 30, 2017
1 parent e32f237 commit aee5fef
Show file tree
Hide file tree
Showing 32 changed files with 672 additions and 613 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ application/logs/*
application/packages/*
!application/packages/.gitkeep
/vendor/
public/uploads/*
!public/uploads/index.html
!public/uploads/.htaccess
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Change Log

## 1.4.0 - 2017-04-30
### Added
- Add `stripTags` option to model.
- Add magic method __set in model to implement strip_tags.
- Add `postList` function to controller template.
- Add `parent::__construct` to Ertikazos_Seeder class.
- Add `make_label` in `make_search_form` function.
- Add `hidden-print` CSS and print only the page content.
- Add `@media print` to styles.
- Add ER_VERSION in footer.

### Changed
- Rewrite `forms` and `rules` methods in model.
- Use forms function instead of forms array in all models.
- Fix CI_numeric in validation.js
- Update .gitignore to ignore uploads folder.
- Fix form_validation if rules array is empty.
- Fix replacing class_name and app_name in language files.
- Fix replacing class_name and app_name in view_list by using str_replace.
- Change make_search_form to accept input array as first parameter.
- Use short array syntax in most of files.
- Use empty instead of isset in make_input helper.
- Change Admin application icons.
- Fix script tag by adding type="text/javascript"

### Removed
- Remove `$this->rules` array from all models.
- Remove useless `$this->permission` from Group_model class.
- Remove bootstrap.css.map line from bootstrap.css

## 1.3.0 - 2017-04-25
### Added
- Add `up` and `down` option for migrate and seed commands.
Expand Down
10 changes: 5 additions & 5 deletions application/controllers/Admin/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function postList()
{
$this->create_button = true;
$this->search_button = true;
$input = $this->input->post(array_keys($this->app->forms['search']));
$input = $this->input->post(array_keys($this->app->forms('search')));
$this->form_validation->set_rules($this->app->rules('search'));

if ($this->form_validation->run() === TRUE)
if (empty($this->app->rules('search')) || $this->form_validation->run() === TRUE)
{
$limit = 10;
$offset = $this->input->get('page');
Expand Down Expand Up @@ -102,7 +102,7 @@ public function getCreate()
*/
public function postCreate()
{
$input = $this->input->post(array_keys($this->app->forms['create']));
$input = $this->input->post(array_keys($this->app->forms('create')));
$this->form_validation->set_rules($this->app->rules('create'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -144,7 +144,7 @@ public function getEdit($id)
*/
public function postEdit($id)
{
$input = $this->input->post(array_keys($this->app->forms['edit']));
$input = $this->input->post(array_keys($this->app->forms('edit')));
$this->form_validation->set_rules($this->app->rules('edit'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -178,7 +178,7 @@ public function postEdit($id)
*/
public function postDelete()
{
$input = $this->input->post(array_keys($this->app->forms['delete']));
$input = $this->input->post(array_keys($this->app->rules('delete')));
$app = $this->app->find($input[$this->app->primaryKey]);
if(is_object($app))
{
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/Admin/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getCreate()
*/
public function postCreate()
{
$input = $this->input->post(array_keys($this->group->forms['create']));
$input = $this->input->post(array_keys($this->group->forms('create')));
$this->form_validation->set_rules($this->group->rules('create'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -125,7 +125,7 @@ public function getEdit($id)
*/
public function postEdit($id)
{
$input = $this->input->post(array_keys($this->group->forms['edit']));
$input = $this->input->post(array_keys($this->group->forms('edit')));
$this->form_validation->set_rules($this->group->rules('edit'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -177,7 +177,7 @@ public function postEdit($id)
*/
public function postDelete()
{
$input = $this->input->post(array_keys($this->group->forms['delete']));
$input = $this->input->post(array_keys($this->group->forms('delete')));
$group = $this->group->find($input[$this->group->primaryKey]);
if(is_object($group))
{
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/Admin/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getCreate()
*/
public function postCreate()
{
$input = $this->input->post(array_keys($this->setting->forms['create']));
$input = $this->input->post(array_keys($this->setting->forms('create')));
$this->form_validation->set_rules($this->setting->rules('create'));

if ($this->form_validation->run() === TRUE)
Expand Down
10 changes: 5 additions & 5 deletions application/controllers/Admin/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public function postList()
$this->create_button = true;
$this->search_button = true;

$input = $this->input->post(array_keys($this->user->forms['search']));
$input = $this->input->post(array_keys($this->user->forms('search')));
$this->form_validation->set_rules($this->user->rules('search'));

if ($this->form_validation->run() === TRUE)
if (empty($this->user->rules('search')) || $this->form_validation->run() === TRUE)
{
$limit = 10;
$offset = $this->input->get('page');
Expand Down Expand Up @@ -104,7 +104,7 @@ public function getCreate()
*/
public function postCreate()
{
$input = $this->input->post(array_keys($this->user->forms['create']));
$input = $this->input->post(array_keys($this->user->forms('create')));
$this->form_validation->set_rules($this->user->rules('create'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -170,7 +170,7 @@ public function getEdit($id)
*/
public function postEdit($id)
{
$input = $this->input->post(array_keys($this->user->forms['edit']));
$input = $this->input->post(array_keys($this->user->forms('edit')));
$this->form_validation->set_rules($this->user->rules('edit'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -251,7 +251,7 @@ public function postEdit($id)
*/
public function postDelete()
{
$input = $this->input->post(array_keys($this->user->forms['delete']));
$input = $this->input->post(array_keys($this->user->forms('delete')));
$user = $this->user->find($input[$this->user->primaryKey]);
if(is_object($user))
{
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/Admin/Watchdog.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getList()
public function postList()
{
$this->search_button = true;
$input = $this->input->post(array_keys($this->watchdog->forms['search']));
$input = $this->input->post(array_keys($this->watchdog->forms('search')));
$this->form_validation->set_rules($this->watchdog->rules('search'));

if ($this->form_validation->run() === TRUE)
Expand Down
18 changes: 14 additions & 4 deletions application/controllers/Creator/commands/Make_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ public function make($type='', $name='', $app='')
if(copy($templates_path.'lang.php', $lang_dir.'/'.strtolower(trim($app_name,'/')).'_lang.php'))
{
$this->_print(str_replace(APPPATH, '',$lang_dir).'/'.strtolower(trim($app_name,'/')).'_lang.php'.' Created', 'success');
// replace {app_name}, {class_name}
$lang_data = file_get_contents($lang_dir.'/'.strtolower(trim($app_name,'/')).'_lang.php');
$lang_data = str_replace('{class_name}', $class_name, $lang_data);
$lang_data = str_replace('{app_name}', trim($app_name,'/'), $lang_data);
file_put_contents($lang_dir.'/'.strtolower(trim($app_name,'/')).'_lang.php', $lang_data);
}
else
{
Expand All @@ -253,6 +258,11 @@ public function make($type='', $name='', $app='')
$app_lang_line = "\$lang['".strtolower(trim($app_name,'/'))."'] = '".ucfirst(trim($app_name,'/'))."';\n";
file_put_contents($lang_dir.'/global_'.strtolower(trim($app_name,'/')).'_lang.php', $app_lang_line, FILE_APPEND);
$this->_print(str_replace(APPPATH, '',$lang_dir).'/global_'.strtolower(trim($app_name,'/')).'_lang.php'.' Created', 'success');
// replace {app_name}, {class_name}
$lang_data = file_get_contents($lang_dir.'/'.strtolower(trim($app_name,'/')).'_lang.php');
$lang_data = str_replace('{class_name}', $class_name, $lang_data);
$lang_data = str_replace('{app_name}', trim($app_name,'/'), $lang_data);
file_put_contents($lang_dir.'/'.strtolower(trim($app_name,'/')).'_lang.php', $lang_data);
}
else
{
Expand Down Expand Up @@ -352,11 +362,11 @@ public function make($type='', $name='', $app='')
continue;
}
$class_data = file_get_contents($view_file);
$class_data = str_ireplace('{class_name}', $class_name, $class_data);
$class_data = str_ireplace('{app_name}', trim($app_name,'/'), $class_data);
$class_data = str_replace('{class_name}', $class_name, $class_data);
$class_data = str_replace('{app_name}', trim($app_name,'/'), $class_data);

$class_data = str_ireplace('{Class_name}', ucfirst($class_name), $class_data);
$class_data = str_ireplace('{App_name}', ucfirst(trim($app_name,'/')), $class_data);
$class_data = str_replace('{Class_name}', ucfirst($class_name), $class_data);
$class_data = str_replace('{App_name}', ucfirst(trim($app_name,'/')), $class_data);

if(file_put_contents(APPPATH.$class_file, $class_data))
{
Expand Down
39 changes: 34 additions & 5 deletions application/controllers/Creator/templates/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,42 @@ public function index()
public function getList()
{
$this->create_button = true;
$this->search_button = true;
$limit = 10;
$offset = $this->input->get('page');
$offset = $this->input->get('page', TRUE);
$count = $this->{model_name}->count();
$this->data['paging'] = make_paging($count, $limit);
$this->data['rows_list'] = $this->{model_name}->rows();
}

/**
*
* List Page for this controller.
*
*/
public function postList()
{
$this->create_button = true;
$this->search_button = true;

$input = $this->input->post(array_keys($this->{model_name}->forms('search')), TRUE);
$this->form_validation->set_rules($this->{model_name}->rules('search'));

if (empty($this->{model_name}->rules('search')) || $this->form_validation->run() === TRUE)
{
$limit = 10;
$offset = $this->input->get('page', TRUE);
$count = $this->{model_name}->count_search($input);
$this->data['paging'] = make_paging($count, $limit);
$this->data['rows_list'] = $this->{model_name}->search($input, $limit, $offset);
}
else
{
set_message($this->form_validation->error_array(), 'error');
redirect('/{app_name}/{class_name}/list');
}
}

/**
*
* Show Page for this controller.
Expand Down Expand Up @@ -74,7 +103,7 @@ public function getCreate()
*/
public function postCreate()
{
$input = $this->input->post(array_keys($this->{model_name}->forms['create']));
$input = $this->input->post(array_keys($this->{model_name}->forms('create')), TRUE);
$this->form_validation->set_rules($this->{model_name}->rules('create'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -116,7 +145,7 @@ public function getEdit($id)
*/
public function postEdit($id)
{
$input = $this->input->post(array_keys($this->{model_name}->forms['edit']));
$input = $this->input->post(array_keys($this->{model_name}->forms('edit')), TRUE);
$this->form_validation->set_rules($this->{model_name}->rules('edit'));

if ($this->form_validation->run() === TRUE)
Expand Down Expand Up @@ -150,8 +179,8 @@ public function postEdit($id)
*/
public function postDelete()
{
$input = $this->input->post(array_keys($this->{model_name}->forms['delete']));
${model_name} = $this->{model_name}->user_find($input[$this->{model_name}->primaryKey]);
$input = $this->input->post(array_keys($this->{model_name}->forms('delete')), TRUE);
${model_name} = $this->{model_name}->find($input[$this->{model_name}->primaryKey]);
if(is_object(${model_name}))
{
${model_name}->delete();
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/Creator/templates/global_lang.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* {app_name} language file
* {app_name} global language file
*/
defined('BASEPATH') OR exit('No direct script access allowed');

24 changes: 15 additions & 9 deletions application/controllers/Creator/templates/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,28 @@ class {class_name} extends ER_Model {
public $permission = 700;

/**
* The array of Form Validation rules.
* please refer to this link
* http://www.codeigniter.com/user_guide/libraries/form_validation.html#rule-reference
* Strip HTML and PHP tags from a string.
*
* @var array
* @var integer
*/
public $rules = [
'*' => ['required']
];
public $stripTags = true;

/**
* The array of the forms input fields.
* The array of the forms input fields with rules.
*
* please refer to this link for rules
* https://www.codeigniter.com/user_guide/libraries/form_validation.html#rule-reference
*
* and this link for forms
* https://www.codeigniter.com/user_guide/helpers/form_helper.html
*
* @var array
*/
public $forms = [
'*' => [],
'*' => [
'input' => '',
'rules' => ''
],
'list' => [],
'edit' => [],
'show' => [],
Expand Down Expand Up @@ -131,4 +136,5 @@ class {class_name} extends ER_Model {
function __construct(){
parent::__construct();
}

}
6 changes: 3 additions & 3 deletions application/controllers/Creator/templates/view_list.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php echo make_search_form('{App_name}/{Class_name}/list', $this->{class_name}->forms('search')) ?>
<?php echo make_search_form($this->{class_name}->forms('search'), '{App_name}/{Class_name}/list') ?>

<div class="panel panel-default">
<div class="panel-body">
Expand All @@ -9,7 +9,7 @@
<?php foreach ($this->{class_name}->forms('list') as $key => $input) { ?>
<th><?php echo lang($input['field']) ?></th>
<?php } ?>
<th><?php echo lang('actions')?></th>
<th class="hidden-print"><?php echo lang('actions')?></th>
</tr>
</thead>
<tbody>
Expand All @@ -18,7 +18,7 @@
<?php foreach ($this->{class_name}->forms('list') as $key => $input) { ?>
<td><?php echo make_input_value($input, $row) ?></td>
<?php } ?>
<td><?php echo make_form_actions($row) ?></td>
<td class="hidden-print"><?php echo make_form_actions($row) ?></td>
</tr>
<?php } ?>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion application/core/ER_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ER_Controller extends CI_Controller{
/**
* The current version of ErtikazOS
*/
const ER_VERSION = '1.3.0';
const ER_VERSION = '1.4.0';

/**
* The variables array
Expand Down
Loading

0 comments on commit aee5fef

Please sign in to comment.