codeigniter 相关问题

CodeIgniter是由EllisLab公司创建的开源PHP Web开发框架,它已被不列颠哥伦比亚理工学院采用。该框架实现了Model-View-Controller设计模式的修改版本。有关CodeIgniter类,方法,函数,语法和用法的问题,请使用此标记。

CodeIgniter 与 Active Records 和 or_like

我有一个管理面板,其中包含从名为“users”的数据库表获取的所有用户信息的视图。 有一个搜索框,我使用活动记录来获取数据。但好像有一个问题...

回答 1 投票 0

集成wepay SDK库与codeigniter2.2配合使用

我正在使用 codeigniter 2.2 处理应用程序,但现在我遇到了将 wepay 库 wepay.php 集成到 codeigniter 库中的问题。任何帮助将不胜感激这是

回答 1 投票 0

Codeigniter 图像库无法一次调整多个图像的大小

我试图在 foreach 循环中一次调整多个图像的大小,但没有这样做。它只调整每页其中一些的大小。 问题我怎样才能确保它在...

回答 2 投票 0

类的Codeigniter方法-undefiend函数

我尝试使用codeignitter完成我的第一步,所以我在现有的类中编写了一个新的方法(函数)。 我尝试使用 codeignitter 完成我的第一步,所以我在现有的类中编写了一个新的方法(函数)。 <?php defined('BASEPATH') or exit('No direct script access allowed'); class App { /** * Options autoload=1 * @var array */ private $options = []; /** * Quick actions create aside * @var array */ private $quick_actions = []; /** * CI Instance * @deprecated 1.9.8 Use $this->ci instead * @var object */ private $_instance; /** * CI Instance * @var object */ private $ci; /** * Show or hide setup menu * @var boolean */ private $show_setup_menu = true; /** * Available reminders * @var array */ private $available_reminders = ['customer', 'lead', 'estimate', 'invoice', 'proposal', 'expense', 'credit_note']; /** * Tables where currency id is used * @var array */ private $tables_with_currency = []; /** * Media folder * @var string */ private $media_folder; /** * Available languages * @var array */ private $available_languages = []; public function __construct() { $this->ci = & get_instance(); // @deprecated $this->_instance = $this->ci; $this->init(); do_action('app_base_after_construct_action'); } /** * Check if database upgrade is required * @param string $v * @return boolean */ public function is_db_upgrade_required($v = '') { if (!is_numeric($v)) { $v = $this->get_current_db_version(); } $this->ci->load->config('migration'); if ((int) $this->ci->config->item('migration_version') !== (int) $v) { return true; } return false; } /** * Return current database version * @return string */ public function get_current_db_version() { $this->ci->db->limit(1); return $this->ci->db->get('tblmigrations')->row()->version; } /** * Upgrade database * @return mixed */ public function upgrade_database() { if (!is_really_writable(APPPATH . 'config/config.php')) { show_error('/config/config.php file is not writable. You need to change the permissions to 755. This error occurs while trying to update database to latest version.'); die; } $update = $this->upgrade_database_silent(); if ($update['success'] == false) { show_error($update['message']); } else { set_alert('success', 'Your database is up to date'); if (is_staff_logged_in()) { redirect(admin_url(), 'refresh'); } else { redirect(site_url('authentication/admin')); } } } /** * Make request to server to get latest version info * @return mixed */ public function get_update_info() { $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_USERAGENT => $this->ci->agent->agent_string(), CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_TIMEOUT => 30, CURLOPT_URL => UPDATE_INFO_URL, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => [ 'update_info' => 'true', 'current_version' => $this->get_current_db_version(), ], ]); $result = curl_exec($curl); $error = ''; if (!$curl || !$result) { $error = 'Curl Error - Contact your hosting provider with the following error as reference: Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl); } curl_close($curl); if ($error != '') { return $error; } return $result; } /** * Return all available languages in the application/language folder * @return array */ public function get_available_languages() { $languages = $this->available_languages; return do_action('before_get_languages', $languages); } /** * Function that will parse table data from the tables folder for amin area * @param string $table table filename * @param array $params additional params * @return void */ public function get_table_data($table, $params = []) { $hook_data = do_action('before_render_table_data', [ 'table' => $table, 'params' => $params, ]); foreach ($hook_data['params'] as $key => $val) { $$key = $val; } $table = $hook_data['table']; $customFieldsColumns = []; $path = VIEWPATH . 'admin/tables/' . $table . '.php'; if (file_exists(VIEWPATH . 'admin/tables/my_' . $table . '.php')) { $path = VIEWPATH . 'admin/tables/my_' . $table . '.php'; } include_once($path); echo json_encode($output); die; } /** * Check if a option value is preset or individual * @param string $name, string $value * @return true/false */ public function option_is_preset($name,$value) { $str="`name`='".$name."' and value='".$value."' "; $this->ci->db->select('id, name, value'); $this->ci->db->where($str); $row = $this->ci->db->get('4U_tbloptions_preset')->row_array(); if ($row['id']>0) { return true; } return false; } /** * All available reminders keys for the features * @return array */ public function get_available_reminders_keys() { return $this->available_reminders; } /** * Get all db options * @return array */ public function get_options() { return $this->options; } /** * Function that gets option based on passed name * @param string $name * @return string */ public function get_option($name) { if ($name == 'number_padding_invoice_and_estimate') { $name = 'number_padding_prefixes'; } $val = ''; $name = trim($name); if (!isset($this->options[$name])) { // is not auto loaded $this->ci->db->select('value'); $str="`name`='".$name."' and `maccid`='".$this->ci->session->userdata('macc_id')."'"; $this->ci->db->where($str); $row = $this->ci->db->get('4U_accounts_tbloptions')->row(); if ($row) { #echo"Wert aus account_tbloptions"; $val = $row->value; } } else { #echo $name.'->'.$val.' Autoload - nicht aus DB!<br>'; $val = $this->options[$name]; } $hook_data = do_action('get_option', ['name' => $name, 'value' => $val]); //Fallback auf Standardwert if ($hook_data['value']=='') { $this->ci->db->select('value'); $this->ci->db->where('name', $name); $row = $this->ci->db->get('4U_tbloptions_preset')->row(); if ($row) { #echo"Wert aus preset"; $val = $row->value; } $hook_data = do_action('get_option', ['name' => $name, 'value' => $val]); } return $hook_data['value']; } /** * Add new quick action data * @param array $item */ public function add_quick_actions_link($item = []) { $this->quick_actions[] = $item; } /** * Quick actions data set from admin_controller.php * @return array */ public function get_quick_actions_links() { $this->quick_actions = do_action('before_build_quick_actions_links', $this->quick_actions); return $this->quick_actions; } /** * Aside.php will set the menu visibility here based on few conditions * @param int $total_setup_menu_items total setup menu items shown to the user */ public function set_setup_menu_visibility($total_setup_menu_items) { $this->show_setup_menu = $total_setup_menu_items == 0 ? false : true; } /** * Check if should the script show the setup menu or not * @return boolean */ public function show_setup_menu() { return do_action('show_setup_menu', $this->show_setup_menu); } /** * Return tables that currency id is used * @return array */ public function get_tables_with_currency() { return do_action('tables_with_currency', $this->tables_with_currency); } /** * Return the media folder name * @return string */ public function get_media_folder() { return do_action('get_media_folder', $this->media_folder); } /** * Upgrade database without throwing any errors * @return mixed */ private function upgrade_database_silent() { $this->ci->load->config('migration'); $beforeUpdateVersion = $this->get_current_db_version(); $this->ci->load->library('migration', [ 'migration_enabled' => true, 'migration_type' => $this->ci->config->item('migration_type'), 'migration_table' => $this->ci->config->item('migration_table'), 'migration_auto_latest' => $this->ci->config->item('migration_auto_latest'), 'migration_version' => $this->ci->config->item('migration_version'), 'migration_path' => $this->ci->config->item('migration_path'), ]); if ($this->ci->migration->current() === false) { return [ 'success' => false, 'message' => $this->ci->migration->error_string(), ]; } update_option('upgraded_from_version', $beforeUpdateVersion); return [ 'success' => true, ]; } /** * Init necessary data */ protected function init() { //Autoloadfelder zuerst alle Presetfelder, die dann mit den Individualfeldern ueberschrieben werden $optionsA = $this->ci->db->select('name, value') ->where('autoload', 1) ->get('4U_tbloptions_preset')->result_array(); $str=" 'maccid'='".$this->ci->session->userdata('macc_id')."' AND 'autoload'='1' "; $optionsB = $this->ci->db->select('name, value') ->where($str) ->get('4U_accounts_tbloptions')->result_array(); $options=array_merge($optionsA, $optionsB); // Loop the options and store them in a array to prevent fetching again and again from database foreach ($options as $option) { $this->options[$option['name']] = $option['value']; } /** * Available languages */ foreach (list_folders(APPPATH . 'language') as $language) { if (is_dir(APPPATH . 'language/' . $language)) { array_push($this->available_languages, $language); } } /** * Media folder * @var string */ $this->media_folder = do_action('before_set_media_folder', 'media'); /** * Tables with currency * @var array */ $this->tables_with_currency = [ [ 'table' => 'tblinvoices', 'field' => 'currency', ], [ 'table' => 'tblexpenses', 'field' => 'currency', ], [ 'table' => 'tblproposals', 'field' => 'currency', ], [ 'table' => 'tblestimates', 'field' => 'currency', ], [ 'table' => 'tblclients', 'field' => 'default_currency', ], [ 'table' => 'tblcreditnotes', 'field' => 'currency', ], [ 'table' => 'tblsubscriptions', 'field' => 'currency', ], ]; } /** * Predefined contact permission * @deprecated 1.9.8 use get_contact_permissions() instead * @return array */ public function get_contact_permissions() { return get_contact_permissions(); } } 现在我想使用这个方法,例如这样 echo"Test1: ".get_option('company_logo_dark'); echo"Test2: ".option_is_preset('company_logo_dark'); 方法“get_option”是类中现有的方法之一。 此 (get_option) 有效,但 option_is_present 会产生错误“调用未定义的函数 option_is_preset() ” 如果我尝试 echo "Test3: ".$this->app->option_is_preset('company_logo',$company_logo); 它会起作用的。 为什么我可以用这种方式使用第一个方法“get_option”( echo "Test: ".get_option(string); " 以及为什么我不能对其他方法执行相同的操作? 非常感谢您对我的支持:-) 在类内部,需要使用伪变量$this echo"Test1: ". $this->get_option('company_logo_dark'); echo"Test2: ". $this->option_is_preset('company_logo_dark', 'some_value'); 取消类的实例: $instance = new App(); echo"Test1: ". $instance ->get_option('company_logo_dark'); echo"Test2: ". $instance ->option_is_preset('company_logo_dark', 'some_value'); 如果类App放在库目录下,可以使用Codeigniter Loader Class $this->load->library('app'); echo"Test1: ". $this->app->get_option('company_logo_dark'); echo"Test2: ". $this->app->option_is_preset('company_logo_dark', 'some_value'); 编辑1 仅当在类外部声明时,才能直接调用 get_option 方法。请看下一个例子 function method_a($var) { echo __METHOD__ . ' : ' . $var .'<br />'; } class MyClass { public function method_a($var) { echo __METHOD__ . ' : ' . $var .'<br />'; $this->method_b($var); } public function method_b($var) { echo __METHOD__ . ' : ' . $var .'<br />'; } } $instance = new MyClass(); $instance->method_a("Test"); method_a("Test"); 这将返回: MyClass::method_a : Test MyClass::method_b : Test method_a : Test 编辑2 根据更新的类,方法option_is_preset需要两个参数,$name和$value,而您尝试仅使用一个参数来调用 echo"Test2: ".option_is_preset('company_logo_dark'); // wrong echo"Test2: ".option_is_preset('company_logo_dark', 'some_value'); // correct 在另一个文件中我发现了 function get_option($name) { $CI = & get_instance(); if (!class_exists('app')) { $CI->load->library('app'); } return $CI->app->get_option($name); } 这解释了为什么可以以函数的正常方式调用“get_option”。 所以我添加了 function option_is_preset($name, $value) { $CI = & get_instance(); if (!class_exists('app')) { $CI->load->library('app'); } return $CI->app->option_is_preset($name, $value); } 现在我可以像函数一样调用新方法:-))

回答 2 投票 0

codeigniter 中的 SQL“VIEW”

我想在 codeigniter 模型中创建一个 SQL 视图。最好的方法是什么?

回答 1 投票 0

连接两个表,其中一个表名称位于另一个表中

我正在属性表中注册各种属性。根据财产类型,使用三个新表(公寓、别墅、土地)来存储特定数据。所以我拥有的是...

回答 2 投票 0

在codeigniter中使用fileuploader.js以及在ajax中使用csrf

如何在 Codeigniter 中通过 csrf、ajax 使用 fileuploader.js? 我正在使用 images_crud 库 http://www.web-and-development.com/image-crud-an-automatic-multiple-image-uploader-for-codeignit...

回答 2 投票 0

来自不同数据库的相同表联合

我有03个MySQL数据库,分别是2022_db、2023_db和2024_db。 03数据库中的所有表和表结构都是相同的并且包含不同的值。我想获得两个数据中的值的总和...

回答 1 投票 0

$this->load->view('view_name',$data,TRUE); 是如何实现的?内部工作

我知道这个方法有什么用了。 查看方法的第三个参数 TRUE 或 FALSE 它在内部如何工作,因为想在核心 php 中创建相同的方法,这在核心 php 中非常有用...

回答 1 投票 0

如何在 codeigniter 中使用这个简单的 acl 库

我以前用过cakephp,现在使用codeigniter,但不幸的是没有任何身份验证或ACL内置库..经过更多搜索我找到了一个很好的库,但我不知道如何使用它....

回答 2 投票 0

CodeIgniter 消息:在实时服务器上“找不到类”

将本地 CodeIgniter 环境 (Windows) 推送到测试服务器 (Linux) 后,我们遇到了以下异常: 遇到未捕获的异常 类型:错误 消息:类'

回答 1 投票 0

Codeigniter 无法加载 CI_Exceptions

我有一个 codeigniter 3 应用程序部署到 ubuntu 服务器。 当我的一个模型(大概)遇到错误时,我收到以下消息: 致命错误:未捕获错误:类“CI_Exceptions”不是

回答 1 投票 0

Codeigniter:带有库的控制器 URI

我有一个可用的控制器和库函数,但我现在需要将 URI 段传递给库以进行决策,但我陷入了困境。 控制器: 功能调查($方法) { $id = $这个->

回答 1 投票 0

如何防止vue、js输入中出现unicode字符?

如何防止 unicode 字符,例如 f.e. vue.js 3 + vuetify 3 + Codeigniter 4 中输入的表情符号?我正在构建管理面板,我可以在其中添加用户帐户。没有原生机制可以...

回答 1 投票 0

Codeignitor 具有特定有限数据随机的分页

我有一个可悲的问题。我无法应对这种情况。请帮忙。 我想从按类别指定的大量数据中检索随机有限的数据。 一般情况下我都可以回来...

回答 1 投票 0

消息:implode():codeigniter 中传递的参数无效

代码: $item_des = implode(',',$this->input->post('item_des')); $item_cost = implode(',',$this->input->post('item_cost')); $service_cost = implode(',',$this->input->post('service_...

回答 3 投票 0

使用 codeigniter 的验证码不起作用

我正在尝试使用 codeigniter 实现验证码功能。但它不显示验证码图像。 这是我的代码: //控制器文件:captcha.php 我正在尝试使用 codeigniter 实现验证码功能。但它不显示验证码图像。 这是我的代码: //控制器文件:captcha.php <?php class Captcha extends CI_Controller { var $controller = "captcha"; var $viewContent = array(); public function __construct() { parent::__construct(); $this->load->view('header'); } /* Function To load captcha view file */ function list_captcha() { // 加载验证码助手 $this->load->helper('captcha'); $data = array( 'img_path' => './captcha/', 'img_url' => 'localhost/demoProject/application/captcha/', 'img_width' => '150', 'img_height' => 24, 'border' => 0, 'expiration' => 7200 ); $captchaArr = create_captcha($data); $this->viewContent['captchaArr'] = $captchaArr; $this->viewContent['captchaWord'] = $captchaArr['word']; //echo"<pre>"; print_r($captchaArr);exit; $this->viewContent['refreshUrl'] = "localhost/ demoProject/" . $this->controller . "/list_" . $this->controller; $this->load->view($this->controller, $this->viewContent); $this->load->view('footer'); } } ?> //查看文件:captcha.php <script> $(document).ready(function(){ $("#captcha").blur(function(){ if($("#captcha").val()== '<?php echo $captchaWord; ?>'){ alert('Captcha match'); }else{ alert('Please enter same word like captcha image.'); } }); }); </script> <table> <tr> <td> Captcha Image </td> <td style="text-align: center"> &nbsp;&nbsp;<?php echo $captchaArr['image']; ?><br> </td> </tr> <tr> <td>Enter the same code here </td> <td style="text-align: center">&nbsp;&nbsp; <?php $data = array('name' => 'captcha', 'id' => 'captcha'); echo form_input($data); ?> </td> </tr> <tr> <td>Can't read the image?</td> <td style="text-align: center">&nbsp;&nbsp;<a href="<?php echo $refreshUrl; ?>">Refresh</a></td> </tr> </table> 我不明白这段代码有什么问题...... 我相信你的问题是这一行: img_url' => 'localhost/demoProject/application/captcha/', 您的 URL 缺少 http:// 协议标识符。 img_url 永远不会被验证码助手修改 - 它直接用于创建 <img> 标签,该标签会直接转储到您的 HTML 输出中。 当浏览器尝试加载图像时,它没有意识到这是一个网址,因此加载失败。 您应该修改这行代码以包含 http:// 部分。更好的是,您应该使用 CodeIgniter 的 base_url() 函数生成 URL,以便您的代码能够灵活应对未来的更改。 您可以像下面这样制作验证码。 $values = array( 'word' => '', //Generate alternate word by default. You can also set your word. 'word_length' => 6, // To set length of captcha word. 'img_path' => './images/', // Create folder "images" in root directory, and give path. 'img_url' => base_url() .'images/', // To store captcha images in "images" folder. 'font_path' => FCPATH.'system/fonts/texb.ttf', 'img_width' => '250', //Set image width. 'img_height' => 50, // Set image height. ); // "create_captcha" is function of "captcha helper", this will set array in helper library. $captcha = create_captcha($values); 注意:- font_path 应包含绝对路径。 Codeigniter 3 验证码使用 GD 库,因此必须在 php.ini 文件中启用它。 ;扩展名=gd2 => 扩展名=gd2 #删除;启用库 还要验证扩展目录 C:\xampp\php74 xt 中的库名称 如果 ext 是“php_gd2.dll”,则库将在 php.ini 中扩展=gd2 如果 ext 是“php_gd.dll”,那么库将在 php.ini 中扩展=gd

回答 3 投票 0

找不到 docker 和 codeigniter 的作曲家

这对我来说是全新的。我正在使用 Docker 和 CodeIgniter。我想在 Docker 中为 CodeIgniter 创建一个映像。我在 Windows 上使用 Docker Desktop。我有一个包含以下代码的 Dockerfile...

回答 1 投票 0

Codeigniter 3 - PHP 8 - 邮件问题

自从 PHP 7.4 更新到 8.1 以来,我通过发送电子邮件收到奇怪的消息。 $配置=数组( '协议' => 'asmtp', 'smtp_host' => 'asmtp.mail.*****.com', ...

回答 1 投票 0

在 codeigniter 中下拉选择更新

表单更新时下拉列表无法显示所选项目。但代码与其他下拉菜单相同 下面的代码可以在下拉菜单中显示所选项目 表单更新时下拉列表无法显示所选项目。但代码和其他下拉菜单是一样的 下面的代码可以在下拉列表中显示所选项目 <div class="col-md-3 pl-pr-1"> <div class="form-group"> <label>Dry Process</label> <?php $dry = $u->dry; ?> <select name="dry" id="dry" class="form-control" required> <option selected disabled>Pilih</option> <option <?php echo ($dry == 'Line Dry/Flat Dry') ? "selected": "" ?>>Line Dry/Flat Dry</option> <option <?php echo ($dry == 'Tumble Dry') ? "selected": "" ?>>Tumble Dry</option> <option <?php echo ($dry == 'All') ? "selected": "" ?>>All</option> <option <?php echo ($dry == 'None') ? "selected": "" ?>>None</option> </select> </div> </div> 下面的代码无法在下拉菜单中显示所选项目 <div class="col-md-3 pl-pr-1"> <div class="form-group"> <label>Technology Concept</label> <?php $technology_concept = $u->technology_concept; ?> <select name="technology_concept" class="form-control" required> <option selected disabled>PILIH</option> <option <?php echo ($technology_concept == 'TECHFIT') ? "selected": "" ?>>TECHFT</option> <option <?php echo ($technology_concept == 'TECHFIT RECHARGER') ? "selected": "" ?>>TECHFIT RECHARGER</option> <option <?php echo ($technology_concept == 'CONTROL') ? "selected": "" ?>>CONTROL</option> <option <?php echo ($technology_concept == 'FORMOTION') ? "selected": "" ?>>FORMOTION</option> <option <?php echo ($technology_concept == 'none') ? "selected": "" ?>>none</option> </select> </div> </div> 我在代码中没有尝试过任何内容,只需重新检查之前的代码,以确保该代码与其他代码相同。但它仍然无法选择更新时的下拉项。 你的代码对我来说看起来不错,除了以下行中的一个拼写错误。 <option <?php echo ($technology_concept == 'TECHFIT') ? "selected": "" ?>>TECHFT</option> 这里,期权的值为“TECHFT”,您的比较值为“TECHFIT”。两者之间的区别是缺少“FIT”中的 I。

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.