I’m trying to load a library with the name Single_column. I create this library and I set it into the libraries folder. I have to mention at this point that I;m using the code Igniter framework. The Sinle_column class contain the following code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Single_column
{
public function render( $id )
{
$CI =& get_instance();
// DB calls
// search for uri in db
$CI->load->model('m_single_column');
$image = $CI->m_single_column->getImageURI( $id );
$text = $CI->m_single_column->getText( $id );
// ==== HEADER
// eventually, this will be loaded from the db
$header_data['title'] = "Single Column Demo";
$header_data['css'][] = "single_column";
$CI->load->view('v_header', $header_data);
// ==== CONTENT
$content_data['content'] = '<div class="content-block">';
$content_data['content'] .= '<div class="image">';
$content_data['content'] .= '<img src="' . base_url() . $image . '" width="200" height="133" alt="my tractor"/>';
$content_data['content'] .= '</div>';
$content_data['content'] .= $text;
$content_data['content'] .= '</div><!-- end content-block-->';
$CI->load->view('v_content', $content_data);
// ==== FOOTER
$CI->load->view('v_footer');
}
}
?>
Now into the controller folder I have a class with the name:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Master extends CI_Controller {
function __construct() {
parent::__construct();
}
public function _remap($method) {
// remap overrides function calls
// search for uri in db
$this->load->model('m_master');
$uri_id = $this->m_master->findURI(uri_string());
$page;
if ($uri_id != false) {
$this->{$page->controller}->render( $page->id );
} else {
show_404(uri_string());
}
}
}
?>
The aforementioned code is from a tutorial and my problem is at the following line:
$this->{$page->controller}->render( $page->id );
The displayed error is the following one:
Fatal error: Cannot access empty property in C:\xampp\htdocs\PhpProject1\application\controllers\master.php on line 24
Actually I realized that it can’t recognize the method ‘render’.
So, I tried the following lines of code into the if statement
$library= Single_column::$uri_id['id'];;
$this->load->library($library);
But I received the following error:
Fatal error: Class ‘Single_column’ not found in C:\xampp\htdocs\PhpProject1\application\controllers\master.php on line 22
Moreover, the $uri_id returns an sql object. ButI want to pass only the id attribute of the object.
Question: How Can I call a library? And how can I pass a value into a method of a class(render method)? Why the aforementioned lines that didn’t work?
Not sure why you’re loading a model into a library.
Make sure your library is also stored in
application/librariesThis is similar to loading CodeIgniter libraries.