标签: codeigniter-3

消息:call_user_func_array() 期望参数 1 是有效的回调

遇到 PHP 错误 严重性:警告

消息:call_user_func_array() 期望参数 1 是有效的回调,类“Error”没有方法“index”

文件名:core/CodeIgniter.php

线路号码:532

回溯:

文件:/var/www/monitors/index.php 行:315 函数:require_once

在我的本地系统中工作正常,但我移动到服务器时出现此错误

codeigniter-3

3
推荐指数
1
解决办法
1万
查看次数

如何在 Twig 中获取数组第一个键名称?

我想获取数组中的键名。

首先,我的管理控制器是这样写的。

class Admin_Controller extends MY_Controller
{
    const FLASHDATA_NAME = "admin_notice";

    public function index()
    {
        $data['flash_message'] = $this->session->flashdata(self::FLASHDATA_NAME);
        $this->twig->display('index', $data);
    }

    public function store()
    {
        $this->session->set_flashdata(self::FLASHDATA_NAME, array('success' => 'create complete'));
        redirect('index');
    }

    public function destroy()
    {
        $this->session->set_flashdata(self::FLASHDATA_NAME, array('danger' => 'delete complete'));
        redirect('index');
    }
}
Run Code Online (Sandbox Code Playgroud)

如果方法已完成,我的闪存数据包含这样的消息。

'flash_message' => array(
    'success' => 'create complete'
);
Run Code Online (Sandbox Code Playgroud)

所以我这样写下我的看法。

{% if flash_message %}
<div class="alert alert-success alert-dismissible">
  <button type="button" class="close" title="close" data-dismiss="alert" aria-hidden="true">x</button>
  <h5><i class="icon fa fa-check"></i>{{ flash_message | first }}</h5>
</div>
{% endif %} …
Run Code Online (Sandbox Code Playgroud)

php twig codeigniter-3

3
推荐指数
1
解决办法
4561
查看次数

Codeigniter 3 textarea

我试图将textarea中的行数限制为4但它给出了错误

Message: Array to string conversion
Run Code Online (Sandbox Code Playgroud)

这是我使用helper类的textarea代码

$textarea_options = array('class' => 'form-control','rows' => 4,   'cols' => 40);

echo form_textarea('vc_desc', set_value('vc_desc'),  $textarea_options);
Run Code Online (Sandbox Code Playgroud)

textarea codeigniter codeigniter-form-helper codeigniter-3

2
推荐指数
1
解决办法
9934
查看次数

Codeigniter表单验证所需的数组

我有一个带有数组字段的表单,允许用户选择多个类别ID。他们必须选择至少一个类别,但可以选择多个类别。我的表单验证需要确保至少指定了一个类别ID,然后对于每个类别ID,都需要检查其是否为有效类别。这是我所拥有的:

$this->form_validation->set_rules('event_categories', 'Categories', 'required');
$this->form_validation->set_rules('event_categories[]', 'Categories', 'integer|exists[category.id]');
Run Code Online (Sandbox Code Playgroud)

我扩展了表单验证库并添加了现成的现存方法,如下所示:

/**
 * Checks to see if a value exists in database table field
 *
 * @access  public
 * @param   string
 * @param   field
 * @return  bool
 */
public function exists($str, $field)
{
    //die("fe");
    list($table, $field)=explode('.', $field);
    $query = $this->CI->db->limit(1)->get_where($table, array($field => $str));

    if($query->num_rows() !== 0) {
        return TRUE;
    }
    else {
        if(!array_key_exists('exists',$this->_error_messages)) {
            $this->CI->form_validation->set_message('exists', "The %s value does not exist");
        }
        return FALSE;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是,即使我提交了有效的类别ID数组,表单验证也未能通过所需的检查,并说即使我已经提交,也必须提交一些。

php codeigniter codeigniter-3

2
推荐指数
1
解决办法
6295
查看次数

如何解决此警告:无法打开流:没有这样的文件或目录

最近,我遇到了一个问题:

Warning:include(C:\xampp\htdocs\crackverbal\application\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\xampp\htdocs\crackverbal\system\core\Exceptions.php on line 269

Warning: include(): Failed opening 'C:\xampp\htdocs\crackverbal\application\views\errors\html\error_php.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\crackverbal\system\core\Exceptions.php on line 269

Warning: include(C:\xampp\htdocs\crackverbal\application\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\xampp\htdocs\crackverbal\system\core\Exceptions.php on line 269

Warning: include(): Failed opening 'C:\xampp\htdocs\crackverbal\application\views\errors\html\error_php.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\crackverbal\system\core\Exceptions.php on line 269
Run Code Online (Sandbox Code Playgroud)

我用过Xamppcodeigniter-3.

codeigniter-3

2
推荐指数
1
解决办法
2万
查看次数

哪个php版支持以下语法

我在本地计算机上使用以下语法

$userRoles = $this->CI->Appusers->getUserRoles()['dbresults'];
Run Code Online (Sandbox Code Playgroud)

带有键'dbresults'的函数返回数组

php arrays codeigniter-3

2
推荐指数
1
解决办法
40
查看次数

Codeigniter文件上传问题

我正在尝试使用codeigniter 3上传图像文件,但它无法正常工作.无论我做什么,它总是说"你没有选择要上传的文件".它在控制台上记录一个错误,当我点击网络选项卡中的错误然后它将我重定向到一个新的选项卡,其中显示错误时,错误500.这是我的HTML代码:

<div id="container">
<h1>Welcome to CodeIgniter!</h1>

<div id="body">
    <form method="post" enctype="multipart/form-data" action="<?php echo base_url('index.php/welcome/upload'); ?>">
        <input type="text" name="username" value="Zahid Saeed">
        <input type="file" name="profile_img">
        <button type="submit">Submit Form</button>
    </form>
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->helper("url");
    }

    public function index()
    {
        $this->load->view('welcome_message');
    }
    public function upload() {  

        $config = array(
            "upload_path" => "./uploads/",
            "allowed_types" => "gif|jpg|png"
        );
        echo "<pre>";
        print_r($this->input->post());
        print_r($_FILES);
        echo "</pre>";

        $this->load->library("upload", $config);
        $this->upload->initialize($config);

        if(!$this->upload->do_upload("profile_img")) { …
Run Code Online (Sandbox Code Playgroud)

php codeigniter file-upload codeigniter-3

2
推荐指数
1
解决办法
2724
查看次数

Angular 2请求标头字段在飞行前响应中,Access-Control-Allow-Headers不允许授权

我正在为服务器应用程序使用codeigniter REST API。客户端为Angular2,在我的REST API中,我给出了基本身份验证。我已设定为

$config['rest_auth'] = 'basic';
Run Code Online (Sandbox Code Playgroud)

$config['rest_valid_logins'] = ['uname' => 'pwd'];
Run Code Online (Sandbox Code Playgroud)

对于CORS Check,我也使用了以下代码,

$config['check_cors'] = TRUE;
$config['allowed_cors_headers'] = [
  'Origin',
  'X-Requested-With',
  'Content-Type',
  'Accept',
  'Access-Control-Request-Method'
];
$config['allowed_cors_methods'] = [
  'GET',
  'POST',
  'OPTIONS',
  'PUT',
  'PATCH',
  'DELETE'
];
$config['allow_any_cors_domain'] = TRUE;
Run Code Online (Sandbox Code Playgroud)

我也尝试过在我的rest控制器中尝试过,

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
Run Code Online (Sandbox Code Playgroud)

我在下面的代码中使用了角度

import { Component, OnInit } from '@angular/core';
import { Http, Headers, RequestOptions  } from '@angular/http';
import { FormGroup, AbstractControl, FormBuilder, Validators } from '@angular/forms';
import …
Run Code Online (Sandbox Code Playgroud)

codeigniter codeigniter-3 codeigniter-restserver angular

2
推荐指数
1
解决办法
4797
查看次数

2
推荐指数
1
解决办法
2064
查看次数

Codeigniter - 在输入字段下面显示错误显示

我试图在输入字段下面显示一个表单错误,但在我单击提交按钮后,它将重定向到另一个页面...

这是我的代码页控制器

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class Pages extends CI_Controller{

        public function view($page = 'home'){
            if(!file_exists(APPPATH.'views/pages/'.$page.'.php')){
                show_404();
            }
            $data['title'] = ucfirst($page);

            $this->load->view('template/header');
            $this->load->view('pages/'.$page);
            $this->load->view('template/footer');
        }

        public function login(){
            echo $this->input->POST('username');
        }

        public function registercheck(){

            echo $this->input->POST('username');
            echo $this->input->POST('pwd');
            echo $this->input->POST('pwd2');
            echo $this->input->POST('fname');
            echo $this->input->POST('position');
            echo $this->input->POST('contactnumber');

            $this->form_validation->set_rules('username', 'USERNAME', 'required|max_lenght[20]');
            $this->form_validation->set_rules('pwd', 'USERNAME', 'required|max_lenght[20]');
            $this->form_validation->set_rules('pwd2', 'UPPERCASE', 'required|max_lenght[20]');
            $this->form_validation->set_rules('fname', 'USERNAME', 'required|max_lenght[20]');
            $this->form_validation->set_rules('position', 'USERNAME', 'required|max_lenght[20]');
            $this->form_validation->set_rules('contactnumber', 'USERNAME', 'required|max_lenght[20]');

            if($this->form_validation->run() == false){
                $this->load->view('pages/register');
            } else{
                echo 'register ok';
            }                   
        }
    } …
Run Code Online (Sandbox Code Playgroud)

javascript php forms codeigniter-3

2
推荐指数
1
解决办法
42
查看次数