codeigniter 相关问题

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

Codeigniter 4 - MySQL 重复条目异常不起作用

我正在使用 Codeigniter v4.4.5 并努力捕获 MySQL 重复条目异常。如果有任何重复的值,那么我想在我的控制器中处理,以便我可以发送相关消息......

回答 1 投票 0

对于 codeigniter 来说,哪一个是最好的 PHP ORM? [已关闭]

这将是 codeigniter 框架的最佳 ORM。我看到了一些类似的问题,但它太旧了,链接不起作用。谁能帮我解决这个问题吗?

回答 2 投票 0

如何使用公共功能登出

我使用下面的代码注销,我不知道如何使用公共函数注销,如何使用按钮模式和使用函数注销,这是我来自login.php的函数 我使用下面的代码注销,我不知道如何使用公共函数注销,如何使用按钮模式和使用函数注销,这是我来自login.php的函数 <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Login extends CI_Controller { //this function will do the login process function __construct() { parent::__construct(); $this->load->library('session'); } function index() { $this->load->library('session'); if ($this->session->username != NULL) { redirect('index.php/report/dashboard_ch'); } else { $this->load->view('login'); } } function do_login() { $this->load->library('session'); $this->load->model('M_login'); $username = $this->input->post('username'); $password = $this->input->post('password'); $dataLogin = false; if ($username === "dimasdev") { $dataLogin = $this->M_login->web_login_hashed($username, $password); } else { $dataLogin = $this->M_login->web_login($username, $password); } if (!$dataLogin) { $res['msg'] = "Invalid username or password"; $res['status'] = false; echo json_encode($res); exit(); } $this->session->set_userdata($dataLogin); $res['msg'] = "Login Success"; $res['dataLoginUsername'] = $dataLogin['username']; $res['status'] = true; echo json_encode($res); } public function logout() { $this->session->sess_destroy(); // Destroy the session $res['msg'] = "Logout Success"; $res['status'] = true; echo json_encode($res); } } 这是我从导航栏注销的模式,我使用按钮注销,但我不知道如何注销 <div class="modal fade" id="logoutModal" tabindex="-1" aria-labelledby="logoutModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="logoutModalLabel">Are you sure you want to log out?</h5> </div> <div class="modal-footer"> <div class="col s2" style="float: center"> <button class="btn btn-danger" href="<?php echo base_url(); ?>index.php/login/logout" class="col s6 modal-close waves-effect waves-green btn-flat yes">OK</button> </div> <div class="col s2" style="float: center"> <button class="btn btn-secondary" data-bs-dismiss="modal" class="col s6 modal-close waves-effect waves-green btn-flat no">Cancel</button> </div> </div> </div> </div> </div> 我使用 vuexy html 框架构建此代码 你能帮忙吗? 只是一个小 HTML 错误。 <a href="URL">LABEL</a> 按钮没有 href 属性,如果您想使用按钮,只需将其用作 LABEL <a href="URL"><button></button></a> 对于你的情况 <div class="col s2" style="float: center"> <a href="<?php echo base_url() . "index.php/login/logout"; ?>"> <button class="btn btn-danger" class="col s6 modal-close waves-effect waves-green btn-flat yes">OK</button> </a> </div>

回答 1 投票 0

带有 hmvc 的 CodeIgniter 4

我正在尝试在 CodeIgniter 4 中使用 HMVC。我之前使用过它,但在版本 3.10 中。我找不到 CI4 的 HMVC 插件。 有人可以帮助我吗?谢谢。 我想使用电子模块...

回答 1 投票 0

Codeigniter Pagination 3.0.4 排序目录和文件

我有一个带有 codeIgniter 3.0.4 分页库的工作文件管理器。 我试图确保它在分页中首先显示目录,然后显示文件。 目前是 codeigniter

回答 1 投票 0

选择选定的CHECKBOX并将选定的行插入数据库

我想将我的问卷答案输入数据库 我在数据库中有这样的表(示例): |编号 |问题|答案| +----+--------------+--------+ | 11 | 11吃晚饭? | 1 | | 1...

回答 2 投票 0

codeigniter上传图片代码url错误

这是关于 codeigniter 图像上传和图像处理的第 9 天 http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-file-uploading-and-image-manipulation/ 这段代码不是

回答 1 投票 0

如何在CI4中自动加载用户定义的类?

我想从 CI4 的本机 \Config\Constants.php 中获取用户定义的常量文件 我想写一个类: 公共类用户常量{ 常量 YEAR = 2024; 常量 MAX ...

回答 1 投票 0

获取 array_merge 和 array_unique 的 php 错误

下面是我尝试唯一/合并的数组和代码 $data['default_new'] = array_unique(array_merge($data['default'], $data['related'])) 大批 ( [0] => 数组 ( [

回答 3 投票 0

将子数组压入同一个数组

我正在尝试将一个数组的内容放入同一个数组中。这里我有一个数组 $mclass,其值例如 大批 ( [0] => stdClass 对象 ( [房间ID] => 1,3,5 [日]=&g...

回答 2 投票 0

消息:使用 foreach 时为 foreach() 提供的参数无效

我在使用foreach时遇到问题,错误代码如下 每次都会遇到 PHP 错误:警告 消息:为 foreach() 提供的参数无效 这是代码...

回答 1 投票 0

onbeforeunload 在 codeigniter 中不起作用

我有非常简单的代码,只是在页面刷新之前显示警告。该代码使用Codeigniter作为框架(不确定Codeigniter是否与该问题相关)。我有一个视图文件(test_v.php)...

回答 2 投票 0

带有 hmvc 的 Codeigniter 4

我正在尝试在codeigniter 4中使用hmvc,我曾经使用过它,但是在3.10版本中,目前我找不到带有hmvc的插件,有人可以帮助我吗?谢谢。 我想使用模块...

回答 1 投票 0

Code Igniter 使用 sql server 2008 进行分页

我正在使用 CI 分页助手和我的 SQL Server 2008 数据库。 我在模型上的函数是: 函数 get_data($limit, $offset) { $billing_db = $this -> 加载 -> 数据库('billing'...

回答 1 投票 0

在 PHPUnit (CIUnit) 中使用 YAML 文件作为数据提供者

我正在使用 PHP CodeIgniter 框架编写一个应用程序。我正在尝试使用 CI_Unit(扩展名为 PHPUnit)来测试应用程序。为了测试模型,我尝试将 YAML 数据提供程序加载为

回答 2 投票 0

在 Codeigniter 中仅选择多行中的一列

我正在考虑效率,但我对此并不确定。 但我有一堆多列的行。我只需要某个特定的所有行中的名称字段...

回答 2 投票 0

在 CodeIgniter 的 editblog.php 视图页面中收到“未定义的数组键”警告 - 如何解决?

有人可以帮助我摆脱这个错误吗,因为我已经陷入这个错误一段时间了,我对摆脱这个错误感到非常沮丧。 错误是: 更新博客 遇到 PHP 错误...

回答 1 投票 0

如何在不刷新页面的情况下重新加载Datatable?

很抱歉我的英语很差。请告诉我使用 datatable jquery 重新加载数据而不刷新页面的过程。我的重载表无法正常工作。 我的观点是: 很抱歉我的英语很差。请告诉我在不使用reload刷新页面的情况下获取datatable jquery数据的过程。我的重载表无法工作。 我的观点是: <table id="table_id" class="table table-striped table-hover table-bordered" cellspacing="0" width="100%"> <thead> <tr style="background-color:#1c2d3f;color:white;"> <th>Kategori <span style="padding-top:5px;font-size:12px;" class="hidden-sm hidden-xs pull-right glyphicon glyphicon-sort"></span></th> <th>Deskripsi <span style="padding-top:5px;font-size:12px;" class="hidden-sm hidden-xs pull-right glyphicon glyphicon-sort"></span></th> <th style="width:200px;">Tipe Kategori <span style="padding-top:5px;font-size:12px;" class="hidden-sm hidden-xs pull-right glyphicon glyphicon-sort"></span></th> <th>Slug <span style="padding-top:5px;font-size:12px;" class="hidden-sm hidden-xs pull-right glyphicon glyphicon-sort"></span></th> <th>Aktif <span style="padding-top:5px;font-size:12px;" class="hidden-sm hidden-xs pull-right glyphicon glyphicon-sort"></span></th> <th>Opsi</th> </tr> </thead> <tbody> <?php foreach($data_kategori as $ambil_data){?> <tr> <td style="background-color:white;"><?php echo $ambil_data->kategori;?></td> <td style="background-color:white;"><?php echo $ambil_data->deskripsi;?></td> <td style="padding-top:15px;background-color:white;"><?php if($ambil_data->parent_kategori == "0"){ echo "<label class='label label-primary'>Kategori Utama</label>"; }else{ echo "<label class='label label-default'>Anak kategori</label>"; }?> </td> <td style="background-color:white;"><?php echo $ambil_data->slug;?></td> <td style="padding-top:15px;background-color:white;"><?php if($ambil_data->aktif == "Y"){ echo "<label class='label label-success'>Aktif</label>"; }elseif($ambil_data->aktif == "N"){ echo "<label class='label label-danger'>Tidak aktif</label>"; }?> </td> <td style="background-color:white;"> <a href="javascript:void(0)" class="btn btn-warning edit" onclick="edit(<?php echo $ambil_data->kat_id;?>)"><i class="glyphicon glyphicon-pencil"></i></a> <a href="javascript:void(0)" class="btn btn-danger hapus" onclick="delete_book(<?php echo $ambil_data->kat_id;?>)"><i class="glyphicon glyphicon-remove"></i></a> </td> </tr> <?php }?> </tbody> 当插入数据时,这是我的jquery: function reload_table(){ table.ajax.reload(null,false); //reload datatable ajax } function save() { var url; if(save_method == 'add') { url = "<?php echo site_url('admin/kategori/proses_tambah_kat ')?>"; } else { url = "<?php echo site_url('index.php/book/book_update')?>"; } // ajax adding data to database $.ajax({ url : url, type: "POST", data: $('#form').serialize(), dataType: "JSON", success: function(data) { //if success close modal and reload ajax table $('#modal_form').modal('hide'); reload_table(); }, error: function (jqXHR, textStatus, errorThrown) { alert('Error adding / update data'); } }); } 有什么我做错了吗? 您可以像这样通过 id 重新加载数据表 $('#table_id').DataTable().ajax.reload(null, false); 或 TableVar.ajax.reload(); 如果您使用 AJAX 来获取 Datatable 的数据,它将起作用。 欲了解更多信息,请参阅此链接

回答 1 投票 0

Jquery Ajax 无法与 Codeigniter 一起使用

我是一个ajax初学者,这里我尝试使用Ajax在同一页面中显示文本框值。 我的控制器代码: 我是 ajax 初学者,这里我尝试使用 Ajax 在同一页面中显示文本框值。 我的控制器代码: <?php class Merchant extends CI_Controller { public function ajaxtest() { $this->load->helper('url'); $this->load->view('ajaxtest'); $fullname = $this->input->post("fullname"); echo $fullname; } } ?> 这是我的查看代码: <head> <script src="<?php echo base_url();?>assets/js/jquery-latest.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#getinfo").click(function() { $.ajax({ type: "POST", url: "<?php echo base_url(); ?>merchant/ajaxtest", data: {textbox: $("#fullname").val()}, dataType: "text", cache:false, success: function(data){ $('#mytext').html(data); } }); return false; }); }); </script> </head> <body> <form method="post"> <input type="text" id="fullname"/> <input type="button" value="getinfo" id="getinfo"/> <span id="mytext"></span> </form> </body> 当我单击按钮 getinfo 时,我想将文本框中的文本显示为跨度文本。但现在什么也没显示.. 更新: 经过专家的意见,我编辑了一些文本(参见我的编辑注释),现在当我单击按钮时,它再次显示一个文本框和一个按钮..!! 您是否使用 Javascript 上的链接设置了 base_url 变量? 因为您的帖子网址包含此变量,您需要设置它才能使其正常工作。因此,请使用 base_url 链接初始化变量。 请参阅下面更正的示例。设置您的域名而不是 yourbaseurl.com <script type="text/javascript"> $(document).ready(function(){ var base_url='http://yourbaseurl.com/index.php/'; $("#getinfo").click(function() { $.ajax({ type: "POST", url: base_url + "merchant/ajaxtest", data: {textbox: $("#fullname").val()}, dataType: "text", cache:false, success: function(data){ $('#mytext').html(data); } }); return false; }); }); </script> 您的 base_url 变量似乎在 JavaScript 中未定义。 获取基本 URL 的一种简单方法是在隐藏输入中回显它,然后在 JS 代码中获取该输入的值: HTML <input type='hidden' id="baseUrl" value="<?php echo base_url(); ?>" /> JS var base_url = $('#baseUrl').val(); $.ajax({ type: "POST", url: base_url + "/merchant/ajaxtest", data: {textbox: $("#fullname").val()}, dataType: "text", // ... 您将文本框作为参数从 ajax 传递到控制器,并尝试获取名称为 fullname 的 POST 数据。这是行不通的,因为您将参数名称作为文本框传入。在您的帖子中访问该内容: class Merchant extends CI_Controller { public function ajaxtest() { $this->load->helper('url'); //you dont need to load view so comment it //$this->load->view('ajaxtest'); $fullname = $this->input->post("textbox"); //not fullname echo $fullname; } } js <script type="text/javascript"> $(document).ready(function(){ var base_url='http://yourbaseurl.com/index.php/'; $("#getinfo").click(function() { var fullname = $("#fullname").val(); alert("Fullname:" + fullname); //do you get this alert $.ajax({ type: "POST", url: base_url + "merchant/ajaxtest", data: {textbox: fullname}, cache:false, success:function(data){ alert("Response:" + data); //do you get this alert $('#mytext').html(data); } }); return false; }); }); </script> 尝试使用这个: <base href="<?=base_url();?>"> <script src="assets/js/jquery-latest.min.js"></script> 这在 ajaxtest 中: $this->load->helper('url'); 并且还注释掉这个: // $this->load->view('ajaxtest'); 此回复可能有点晚了 - 但有人可能会在寻找解决方案时发现这一点。 我在使用 Codeigniter 和 JQuery ajax/post 响应时遇到了同样的问题。无论我如何尝试,我都无法让它发挥作用。 最后发现是 php_error 导致了这个问题。一旦我删除它,我的帖子/回复一切正常。

回答 5 投票 0

使用 CodeIgniter 数据库伪造检查表中是否存在多列

我想创建迁移来更新表。所以我想在执行之前检查数据库表中是否存在列以消除重复列的错误。有没有使用 db forge 进行检查

回答 2 投票 0

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