我无法为我的表单设置if writable表单验证。
我知道codeigniter表单验证是post。我认为这可能会起作用。
如果文件或文件夹不可写,我需要能够显示我的错误chomd 644 or 777
目前已知错误正在显现。
我有表单验证库和表单自动加载。
控制器
<?php
class Step2 extends MX_Controller {
public function index() {
$this->lang->load('install/english', 'english');
$this->lang->load('install/english', 'english');
$this->load->library('form_validation');
$this->form_validation->set_rules('cache', 'Cache', 'required');
$this->form_validation->set_rules('logs', 'Logs', 'required');
$this->form_validation->set_rules('logs', 'Logs', 'required');
$this->form_validation->set_rules('modules/download', 'modules/download', 'required');
$this->form_validation->set_rules('modules/image', 'modules/image', 'required');
$this->form_validation->set_rules('modules/image/cache', 'modules/image/cache', 'required');
$this->form_validation->set_rules('modules/image/catalog', 'modules/image/catalog', 'required');
if($this->form_validation->run()) {
$this->response->redirect($this->url->link('step3'));
} else {
$this->document->setTitle($this->lang->line('heading_step_2'));
$data['config'] = FCPATH . APPPATH . 'config/config.php';
$data['cache'] = FCPATH . APPPATH . 'cache';
$data['logs'] = FCPATH . APPPATH . 'logs';
$data['download'] = FCPATH . APPPATH . 'modules/download';
$data['image'] = FCPATH . APPPATH . 'modules/image';
$data['image_cache'] = FCPATH . APPPATH . 'modules/image/cache';
$data['image_data'] = FCPATH . APPPATH . 'modules/image/catalog';
if (is_really_writable(APPPATH . 'cache') == false) {
echo "Cache Folder is not writable";
echo "</br>";
}
if (is_really_writable(FCPATH . APPPATH . 'logs') == false) {
echo "Logs Folder is not writable";
echo "</br>";
}
if (is_really_writable(FCPATH . APPPATH . 'modules/download') == false) {
echo "Downloads Folder is not writable";
echo "</br>";
}
if (is_really_writable(FCPATH . APPPATH . 'modules/image') == false) {
echo "Image Folder is not writable";
echo "</br>";
}
if (is_really_writable(FCPATH . APPPATH . 'modules/image/cache') == false) {
echo "Image Cache Folder is not writable";
echo "</br>";
}
if (is_really_writable(FCPATH . APPPATH . 'modules/image/catalog') == false) {
echo "Downloads file is not writable";
echo "</br>";
}
$data['back'] = $this->url->link('step1');
$this->response->setOutput($this->load->view('template/step2', $data));
}
}
}
查看
<?php echo validation_errors('<div class="error">', '</div>'); ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<p><?php echo $text_install_directory; ?></p>
<fieldset>
<table class="table">
<thead>
<tr>
<td align="left"><b><?php echo $text_directory; ?></b></td>
<td align="left"><b><?php echo $text_status; ?></b></td>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $cache . '/'; ?></td>
<td name="cache"><?php if (is_writable($cache)) { ?>
<span class="text-success"><?php echo $text_writable; ?></span>
<?php } else { ?>
<span class="text-danger"><?php echo $text_unwritable; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $logs . '/'; ?></td>
<td name="logs"><?php if (is_writable($logs)) { ?>
<span class="text-success"><?php echo $text_writable; ?></span>
<?php } else { ?>
<span class="text-danger"><?php echo $text_unwritable; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $download . '/'; ?></td>
<td><?php if (is_writable($download)) { ?>
<span class="text-success"><?php echo $text_writable; ?></span>
<?php } else { ?>
<span class="text-danger"><?php echo $text_unwritable; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $image . '/'; ?></td>
<td><?php if (is_writable($image)) { ?>
<span class="text-success"><?php echo $text_writable; ?></span>
<?php } else { ?>
<span class="text-danger"><?php echo $text_unwritable; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $image_cache . '/'; ?></td>
<td><?php if (is_writable($image_cache)) { ?>
<span class="text-success"><?php echo $text_writable; ?></span>
<?php } else { ?>
<span class="text-danger"><?php echo $text_unwritable; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $image_data . '/'; ?></td>
<td><?php if (is_writable($image_data)) { ?>
<span class="text-success"><?php echo $text_writable; ?></span>
<?php } else { ?>
<span class="text-danger"><?php echo $text_unwritable; ?></span>
<?php } ?>
</td>
</tr>
</tbody>
</table>
</fieldset>
<div class="buttons">
<div class="pull-left"><a href="<?php echo $back; ?>" class="btn btn-default"><?php echo $button_back; ?></a></div>
<div class="pull-right">
<input type="submit" value="<?php echo $button_continue; ?>" class="btn btn-primary" />
</div>
</div>
</form>
我的更新我现在可以收到错误,显示我必须在控制器上添加它。
$this->form_validation->set_rules('cache', '', 'callback_isWritable');
public function isWritable() {
$folder_cache = FCPATH . APPPATH . 'cache';
if (is_writable($folder_cache )) {
return true;
} else {
$this->form_validation->set_message('isWritable', 'Cache Folder ' . '<b>' . $folder_cache . '</b>' . ' is not writable');
return false;
}
}
答案 0 :(得分:0)
您需要创建一个自定义回调来用于此目的。
您需要在与验证码相同的类中创建这样的函数。
//by adding the extra underscore the method is not reachable from the browser
public function _isWritable($filename)
{
if (! is_really_writable(APPPATH . 'cache')) {
$this->form_validation->set_message('isWritable', 'Cache Folder is not writable');
return false;
}
//additional if statements to check each of the additional folders...
return true;
}
然后你只需将它添加到像这样的规则
$this->form_validation->set_rules('saveChecks', '', 'callback__isWritable');
您可以通过执行
输出表单错误echo form_error('saveChecks');