简体   繁体   中英

Code Igniter: A PHP Error was encountered Severity: Notice Message: Undefined variable: page Filename: admin/display_page.php Line Number: 18

I'm getting the following error inside the admin page where I can view the table containing all the pages:

A PHP Error was encountered Severity: Notice

Message: Undefined variable: page

Filename: admin/display_page.php

Line Number: 18

Any idea what I should change? the code inside display_page.php is similar to the display_news.php but for some reason, the backend page related to the pages shows an error and the one for the news is working fine.

That's the code inside display_page.php:

<form name="listing" id="listing" action="<?php echo base_url(); ?>admin/page/delete" method="post">

<input name="lang" type="hidden" value="<?php echo $lang;?>" />

<table width="900" border="0" cellspacing="0" cellpadding="0" class="listingTbl">
  <tr>

    <th width="100">Page Id</th>
      <th>Page Title</th>
    <th width="150"><a class="filter-column" href="?sort=page_group">Page Group</a></th>
    <th width="100">Actions</th>
  </tr>
  <?
  foreach($page_s as  $page){?>
  <tr>

    <td><?php echo $page["page_id"];?>&nbsp;</td>
    <td><?php echo $page["page_title"];?>&nbsp;</td>
    <td><?php echo $page["page_group"];?>&nbsp;</td>
    <td>
    <a href="<?php echo base_url(); ?>admin/page/action/<?php echo $page["lang"];?>/<?php echo $page["page_id"];?>">
    <img src="<?php echo base_url(); ?>admin_images/edit.png" width="16" height="16" />
    </a>
    </td>
  </tr>
  <? }?>
</table>
</form>

<div id="delete-block"><a href="#" id="delete-items"><img src="<?php echo base_url(); ?>admin_images/drop.png" width="16" height="16" align="absmiddle" > Delete Checked Items</a></div>
<div id="pagination-block">Go to <?php echo $this->pagination->create_drop_down();?></div>

EDIT:

That's the code related to the pages in the controller file:

function index()
{

    $sort = isset($_GET['sort']) ? $_GET['sort'] : null;

    $lang = ( isset($this->uri_arr["lang"]) ) ? $this->uri_arr["lang"] : "en";

    ///////////////////////////////////////////////////////////

    $current_page = (isset($this->uri_arr["page"])) ? $this->uri_arr["page"] : 1 ;
    $per_page = "20";
    $offset =  ($current_page-1) * $per_page;

    $config["base_url"] = base_url()."admin/page/index/";
    $config["total_rows"] = $this->Page_model->num_page_s(array( "lang" => $lang ));
    $config['per_page'] = '20';
    $this->pagination->initialize($config);

    ///////////////////////////////////////////////////////////
    $order_by = (isset($sort) && $sort == 'page_group') ? 'page_group ASC' : null;

    $pages = $this->Page_model->get_all_page_s( $per_page , $offset , $lang, $order_by );

    $this->load->vars( array( "page_s" => $pages, "lang" => $lang ));

    $this->data["main_content"] = $this->load->view( "admin/display_page" , "" , TRUE );

    $this->load->view( 'admin/template' , $this->data );

}

My guess is you don't have short_open_tag enabled and so this line :-

<? foreach($page_s as $page){?>

isn't working. You would need to change it to this:-

<?php foreach($page_s as $page){ ?>

add this line to your controller when loading view pass $data variable to view.

$data['page_s']=$your_array;
$this->load->view('file_path/file_name',$data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM