简体   繁体   中英

A PHP Error was encountered Severity: Notice Message: Undefined property: CI_Loader::$p Filename: Templates/public.php Line Number: 24

I have gone through this forum and tried all the options provided but nothing is working for me.

I developed a CMS using some Codeigniter tutorial. On my PC everything works well. But on the remote server, it has failed to work. Below is the code. Thanks in advance.

Here is the view

Currently editing:

Currently editing:

load->view('Templates/head'); ?>

 <div class="container"> <!-- Static navbar --> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#"><?php echo $this->brand; ?></a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> <li><a href="<?php echo base_url(); ?>">Home</a></li> <li><a href="<?php echo base_url(); ?>pages/contact">Contact</a></li> <?php //$CI =& get_instance(); ?> <?php if ($this->p) : ?> //liine 24 <?php foreach($this->p as $page) : ?> <li><a href="<?php echo base_url(); ?>pages/show/<?php echo $page->slug; ?>"><?php echo $page->title; ?></a></li> <?php endforeach; ?> <?php else : ?> <?php endif; ?> </ul> </div><!--/.nav-collapse --> </div><!--/.container-fluid --> </nav> <!-- Main component for a primary marketing message or call to action --> <!-- <div class="well"> --> <?php $this->load->view('Templates/slider'); ?> <!-- </div> --> <div style="margin-top:-55px; min-height: 300px;"> <div class="col-md-12"> <?php $this->load->view($main); ?> </div> </div> <div class="well"> <?php $this->load->view('Templates/foot'); ?> </div> </div> <!-- /container --> 

Controller

 class Pages extends Public_Controller { function __construct(){ parent::__construct(); //$this->load->library('p'); } public function index() { $data['featured_pages'] = $this->Page_model->get_featured(); $this->template->load('public', 'default', 'pages/index', $data); } public function show($slug){ $data['p'] = $this->Page_model->get_by_slug($slug); $this->template->load('public', 'default', 'pages/show', $data); } public function contact(){ // $this->template->load('public', 'default', 'pages/contact') die('contact'); } 

}

The error message comes from that $this->p is not defined. First, it seem that you define $p not $this->p in the controller ( show() -method):

$data['p'] = $this->Page_model->get_by_slug($slug);

So the most probable solution would be to change row 24 and 25 to:

<?php if (isset($p) && $p) : ?> //liine 24
        <?php foreach($p as $page) : ?>

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