Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 扩展Codeigniter 2.0中的控制器_Php_Codeigniter - Fatal编程技术网

Php 扩展Codeigniter 2.0中的控制器

Php 扩展Codeigniter 2.0中的控制器,php,codeigniter,Php,Codeigniter,我想问一下,在codeigniter中扩展控制器的正确方法是什么。因为现在我遇到了一个致命错误:在中找不到类'ApiController',这两个文件位于同一目录api文件夹中。这是我的密码: <?php //EchelonApiController.php class EchelonApiController extends ApiController { public function __construct() { parent::__construct();

我想问一下,在codeigniter中扩展控制器的正确方法是什么。因为现在我遇到了一个
致命错误:在
中找不到类'ApiController',这两个文件位于同一目录
api
文件夹中。这是我的密码:

<?php
//EchelonApiController.php
class EchelonApiController extends ApiController {

    public function __construct() {
       parent::__construct();
    }

    public function index(){
        echo 'asd';
    }
}


<?php
// ApiController.php
class ApiController extends CI_Controller {

    public $table;

    public function __construct(){

        parent::__construct();

        $this->load->models("api/".$table);
    }

    public function index(){

    }
}

也许这会对你有所帮助


这似乎是类似的情况,可能文件放置是您的问题的一部分。

将ApicController放在应用程序/核心目录中。

在扩展它之前,您需要包含基类文件

<?php
//EchelonApiController.php

require "path/to/file/ApiController.php";

class EchelonApiController extends ApiController {

    public function __construct() {
       parent::__construct();
    }

    public function index(){
       echo 'asd';
    }
}
否则,只需借助于APPPATH常量添加正确的路径即可。

类欢迎扩展CI_控制器{

function __construct()
{
    parent::__construct();
    $this->load->database();
    $this->load->model("User_model");
    $this->load->helper("form");
    $this->load->helper("url");
}
/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see https://codeigniter.com/user_guide/general/urls.html
 */
function do_upload($name){
            $this->load->helper("form");

$config['upload_path'] = 'upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '102400';
$config['max_height']  = '76800';
$this->load->library('upload', $config);

$this->upload->initialize($config);
if (!$this->upload->do_upload($name)) {


}else{
$databasea['upload_data'] = $this->upload->data();
$this->load->library('image_lib');
return $databasea['upload_data']['file_name'];
}

}
public function index()
{
    if(isset($_POST['resgisterd'])){

        $insert['fname'] = $_POST['fname'];
        $insert['lname'] = $_POST['lname'];
        $insert['address'] = $_POST['address'];
        $insert['country'] = $_POST['country'];
        $insert['state'] = $_POST['state'];
        $insert['city'] = $_POST['city'];
        $insert['tittle'] = $_POST['tittle'];
        $insert['company'] = $_POST['company'];
        $insert['phone'] = $_POST['phone'];
        $insert['email'] = $_POST['email'];
        $insert['password'] = $_POST['password'];

        $insert['image'] = $this->do_upload('image');

        $this->User_model->insertrow($insert,'candidate');

    }



    $data['country'] = $this->User_model->fetchrow('country');
    $this->load->view('front/reg',$data);
}

function getstate($id){

     $whr['country_id'] = $id;
     $state = $this->User_model->fetchrowedit('state',$whr);
    $option = '';
    foreach ($state as $states ) {
    $option = '<option>Select State</option>';

    $option .= '<option value="'.$states->state_id.'">'.$states->state_name.'</option>';

    }

    print_r($option);
}

函数消息_框(){

}

function __construct()
{
    parent::__construct();
    $this->load->database();
    $this->load->model("User_model");
    $this->load->helper("form");
    $this->load->helper("url");
}
/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see https://codeigniter.com/user_guide/general/urls.html
 */
function do_upload($name){
            $this->load->helper("form");

$config['upload_path'] = 'upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '102400';
$config['max_height']  = '76800';
$this->load->library('upload', $config);

$this->upload->initialize($config);
if (!$this->upload->do_upload($name)) {


}else{
$databasea['upload_data'] = $this->upload->data();
$this->load->library('image_lib');
return $databasea['upload_data']['file_name'];
}

}
public function index()
{
    if(isset($_POST['resgisterd'])){

        $insert['fname'] = $_POST['fname'];
        $insert['lname'] = $_POST['lname'];
        $insert['address'] = $_POST['address'];
        $insert['country'] = $_POST['country'];
        $insert['state'] = $_POST['state'];
        $insert['city'] = $_POST['city'];
        $insert['tittle'] = $_POST['tittle'];
        $insert['company'] = $_POST['company'];
        $insert['phone'] = $_POST['phone'];
        $insert['email'] = $_POST['email'];
        $insert['password'] = $_POST['password'];

        $insert['image'] = $this->do_upload('image');

        $this->User_model->insertrow($insert,'candidate');

    }



    $data['country'] = $this->User_model->fetchrow('country');
    $this->load->view('front/reg',$data);
}

function getstate($id){

     $whr['country_id'] = $id;
     $state = $this->User_model->fetchrowedit('state',$whr);
    $option = '';
    foreach ($state as $states ) {
    $option = '<option>Select State</option>';

    $option .= '<option value="'.$states->state_id.'">'.$states->state_name.'</option>';

    }

    print_r($option);
    function getcity($sid){

        $whr['state_id'] = $sid;
        $city12 = $this->User_model->fetchrowedit('city',$whr);
        echo $this->db->last_query();
            foreach ($city12 as $city123 ) {
        $option1 = '';
        $option1 .= '<option value="'.$city123->city_id.'">'.$city123->city_name.'</option>';



            }
            print_r($option1);
    }


    function checkremote(){

        $uName['email'] = $this->input->post('email');
        $isUNameCount = $this->User_model->alreadyexits('candidate',$uName);
        if($isUNameCount > 0){
                echo 'false';
        }else{

             echo 'true';

            }
        }



function login(){

    if(isset($_POST['login'])){

        $log['email'] = $_POST['email'];
        $log['password'] = $_POST['password'];
        $details = $this->User_model->fetchrowlogin($log,'candidate');

        if(count($details)){
            $ids = $details['id'];
            $email = $details['email'];
            $fname = $details['fname'];

            $this->session->set_userdata(array(

                'custid' => $ids,
                'emailid'=> $email,
                'fname'=> $fname,
            ));
        redirect('http://localhost/test27/index.php/welcome/dashboard');
        }else{

        redirect(base_url().'front1');


        }

    }



    $this->load->view('front/login');
}
$id = $this->session->userdata('custid');   
$whr['id']=$id;

if(isset($_POST['resgisterd'])){

        $insert['fname'] = $_POST['fname'];
        $insert['lname'] = $_POST['lname'];
        $insert['address'] = $_POST['address'];
        $insert['country'] = $_POST['country'];
        $insert['state'] = $_POST['state'];
        $insert['city'] = $_POST['city'];
        $insert['tittle'] = $_POST['tittle'];
        $insert['company'] = $_POST['company'];
        $insert['phone'] = $_POST['phone'];

        if(!empty($_FILES['image']['name'] && isset($_FILES['image']['name']))){
        $insert['image'] = $this->do_upload('image');

    }else{

                    $insert['image'] = $_POST['preimage'];

    }
            $whrs['id']=$id;

        $this->User_model->updaterow($insert,'candidate',$whrs);

        echo $this->db->last_query();
 redirect('http://localhost/test27/index.php/welcome/dashboard');

    }
    $data['info'] = $this->User_model->fetchrowedit('candidate',$whr);
    $data['country'] = $this->User_model->fetchrow('country');
    $this->load->view('front/dashboard',$data);
$id = $this->session->userdata('custid');

$data['message_info']= $this->User_model->messages_list($id);


$this->load->view('front/message_box',$data);

}

function perticular($id){

$id1 = $this->session->userdata('custid');

$data['message_info']= $this->User_model->messages_perticular($id,$id1);
echo $this->db->last_query();

$this->load->view('front/message_box',$data);

}

function login(){

        if(isset($_POST['login'])){

            $login['email'] = $_POST['email'];
            $login['password'] = $_POST['password'];

            $
        }


}


function logout(){

    $this->session->unset_userdata('custid');
    $this->session->unset_userdata('emailid');
    $this->session->unset_userdata('fname');

}