codeigniter A PHP Error was encountered Severity:Warning Message:Undefined variable $poke

sxpgvts3  于 7个月前  发布在  PHP
关注(0)|答案(1)|浏览(58)

A PHP Error was encountered严重性:警告
Message:Undefined variable $poke
文件夹:views/pokeview.php
产品编号:44
回溯:
会话信息:SESSION_ID = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
会话信息:SESSION_ID = mkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
会话信息:SESSION_ID = 433333333333332
遇到未捕获的异常类型:TypeError
sizeof():参数#1($value)必须是Countable类型|数组,null给定
会话信息:SESSION_ID = pkbjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
产品编号:44
回溯:
会话信息:SESSION_ID = mkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
会话信息:SESSION_ID = 433333333333332
https://i.stack.imgur.com/ZHsx6.png

    • 这是我的控制器**
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

    class Nav extends CI_Controller{

        public function __construct() {
            parent::__construct();
            $this->load->helper('url');
            $this->load->model('Pokemodel');
        }

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

        public function pokemonTable() {
            $pokemon = array(
            'poke' => $this->Pokemodel->poketable()
            );
            $this->load->view('pokeview', $pokemon);
        }
        

        public function insertPokemon(){
            $this->load->view('insert_form');
        }
        public function pokemonInsert() {
            $pokeName = $this->input->post('pokeName');
            $typeOne = $this->input->post('typeOne');
            $typeTwo = $this->input->post('typeTwo');
        
            $this->load->model('Pokemodel');
            $this->Pokemodel->pokeinsert($pokeName, $typeOne, $typeTwo);
        
            $data['poke'] = $this->Pokemodel->poketable();
            
            $this->load->view('pokeview', $data);
        }

        public function searchPokemon(){
            $searchTerm = $this->input->get('search');
            $this->load->model('Pokemodel');
            $data['poke'] = $this->Pokemodel->searchPokemon($searchTerm);
            $this->load->view('pokeview', $data);
        }
        
    
        public function viewPokemon($pokeName) {
            $data['pokemon'] = $this->Pokemodel->get_pokemon_by_name($pokeName);
            $this->load->view('view_pokemon', $data);
        }
        
        public function deletePokemon($pokeName) {
            $this->Pokemodel->delete_pokemon($pokeName);
            redirect('Nav/pokemonTable');
        }    
        
        
}
?>

字符串

    • 型号**
<?php

    class Pokemodel extends CI_Model{
        public function poketable(){
            $q = $this->db->query("SELECT * FROM pokedex ORDER BY pokeName ASC");
            return $q->result();
        }
                
     public function pokeinsert($pokeName, $typeOne, $typeTwo) {

        $d = array(
            'pokeName' => $pokeName,
            'typeOne' => $typeOne,
            'typeTwo' => $typeTwo
        );

         $this->db->insert('pokedex', $d);
     } 

     public function searchPokemon($searchTerm){
        if ($searchTerm !== null) {
            $this->db->like('pokeName', $searchTerm);
            $this->db->or_like('typeOne', $searchTerm);
            $this->db->or_like('typeTwo', $searchTerm);
        }

        $q = $this->db->get('pokedex');
        return $q->result();
    }
    
    public function get_pokemon_by_name($pokeName){
        $q = $this->db->get_where('pokedex', array('pokeName' => $pokeName));
        return $q->row();
    }

    public function delete_pokemon($pokeName){
        $this->db->where('pokeName', $pokeName);
        $this->db->delete('pokedex');
    }
    
}
?>

    • 查看**
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
    <title>Pokemon</title>
    <nav class="navbar navbar-expand-lg bg-body-tertiary">
  <div class="container-fluid">
    <a class="navbar-brand" href="http://localhost/llames3/index.php/Nav/pokemonTable">Pokedex</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="http://localhost/llames3/index.php/Nav/pokemonTable">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="http://localhost/llames3/index.php/Nav/insertPokemon">Insert</a>
        </li>
       
      </ul>
      <form class="d-flex" action="http://localhost/llames3/index.php/Nav/searchPokemon" method="get">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" name="search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>
</head>
<body>
<div class="container">
<table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">Pokemon Name</th>
      <th scope="col">Type One</th>
      <th scope="col">Type Two</th>
    </tr>
  </thead>
  <tbody>
      <?php for($i = 0; $i < sizeof($poke); $i++) {?>
                <tr>
                <th scope="row"><?php echo $poke[$i]->pokeName; ?></th>
                <td><?php echo $poke[$i]->typeOne; ?></td>
                <td><?php echo $poke[$i]->typeTwo; ?></td>
                <td>
                  <a href="<?= base_url('index.php/Nav/viewPokemon/' . $poke[$i]->pokeName) ?>" class="view-btn" >View</a>
                  <a href="<?= base_url('index.php/Nav/deletePokemon/' . $poke[$i]->pokeName) ?>" class="delete-btn">Delete</a>
                </td>
                </tr>
        <?php } ?>
  </tbody>
</table>
</div>
</body>
</html>


pokedex数据库不会显示在我的工作。谁能帮我调试这个?

neekobn8

neekobn81#

你要打开index对吧?
为什么不把poke变量也加到index方法中?

Controller代码应该是这样的:

<?php

public function index() {
    $pokemon = array(
        'poke' => $this->Pokemodel->poketable()
    );
    $this->load->view('pokeview', $pokemon);
}

字符串
完整代码:

<?php defined('BASEPATH') or exit('No direct script access allowed');
    
    class Nav extends CI_Controller {
    
        public function __construct() {
            parent::__construct();
            $this->load->helper('url');
            $this->load->model('Pokemodel');
        }
    
        public function index() {
            // Add this line
            $pokemon = array(
                'poke' => $this->Pokemodel->poketable()
            );
            $this->load->view('pokeview', $pokemon);
        }
    
        public function pokemonTable() {
            $pokemon = array(
                'poke' => $this->Pokemodel->poketable()
            );
            $this->load->view('pokeview', $pokemon);
        }
    
    
        public function insertPokemon() {
            $this->load->view('insert_form');
        }
        public function pokemonInsert() {
            $pokeName = $this->input->post('pokeName');
            $typeOne = $this->input->post('typeOne');
            $typeTwo = $this->input->post('typeTwo');
    
            $this->load->model('Pokemodel');
            $this->Pokemodel->pokeinsert($pokeName, $typeOne, $typeTwo);
    
            $data['poke'] = $this->Pokemodel->poketable();
    
            $this->load->view('pokeview', $data);
        }
    
        public function searchPokemon() {
            $searchTerm = $this->input->get('search');
            $this->load->model('Pokemodel');
            $data['poke'] = $this->Pokemodel->searchPokemon($searchTerm);
            $this->load->view('pokeview', $data);
        }
    
    
        public function viewPokemon($pokeName) {
            $data['pokemon'] = $this->Pokemodel->get_pokemon_by_name($pokeName);
            $this->load->view('view_pokemon', $data);
        }
    
        public function deletePokemon($pokeName) {
            $this->Pokemodel->delete_pokemon($pokeName);
            redirect('Nav/pokemonTable');
        }
    }

相关问题