Welcome Guest, Not a member yet? Register   Sign In
Problem in creating class
#1

[eluser]Unknown[/eluser]
When i am creating a library in application and trying to load it.
Loader checks for the same in both system and application folder.
when I create the sam elibrary in system also it gives the parse error.

Please suggest the solution.



library class code:

<?php
class MyMenu{
function show_menu(){
$obj =& get_instance();
$obj->load->helper('url');
$menu = "<ul>";
$menu .= "<li>";
$menu .= anchor("books/main","List of Books");
$menu .= "</li>";
$menu .= "<li>";
$menu .= anchor("books/input","Input Book");
$menu .= "</li>";
$menu .= "</ul>";

return $menu;
}
}
?&gt;


controller class code:

&lt;?php
class books extends CI_Controller
{
////Constructor
public function __construct(){
parent::__construct();
}

function main(){
$this->load->library('MyMenu');
$menu = new MyMenu;
$data['menu'] = $menu->show_menu();
$this->load->view('books_main',$data);
}

function input(){
$this->load->library('MyMenu');
$menu = new MyMenu;
$data['menu'] = $menu->show_menu();
$this->load->view('books_input',$data);
}

}
?&gt;
#2

[eluser]noideawhattotypehere[/eluser]
If you use $this->load->library(‘MyMenu’); you should call it $this->MyMenu->show_menu();
anyway exact error could help a lot, and next time wrap your source into code tags.




Theme © iAndrew 2016 - Forum software by © MyBB