Part of the EllisLab Network
   
1 of 2
1
Application layout
Posted: 29 June 2007 10:00 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  84
Joined  06-21-2007

I just read the wiki article http://codeigniter.com/wiki/layout_library/

and tried to do this at my application but I get a error
Fatal error: Call to a member function on a non-object in /home/worldofm/public_html/apartments/system/application/controllers/chisinau.php on line 12

When I tried to find out what’s the problem I saw that load object doesn’t exist in the controller

chisinau Object
(   [_ci_ob_level] =>
  [_ci_view_path] =>
  [_ci_is_php5] =>
  [_ci_is_instance] =>
  [_ci_cached_vars] => Array
      (
      )

  [_ci_classes] => Array
      (
      )

  [_ci_models] => Array
      (
      )

  [_ci_helpers] => Array
      (
      )

  [_ci_plugins] => Array
      (
      )

  [_ci_scripts] => Array
      (
      )

  [_ci_varmap] => Array
      (
        [unit_test] => unit
        [user_agent] => agent
      )

  [_ci_scaffolding] =>
  [_ci_scaff_table] =>
)

What is the problem?

 Signature 

everything about Moldova

Profile
 
 
Posted: 29 June 2007 11:15 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  208
Joined  06-12-2006

can you post the code in your controller chisinau.php ?

Profile
 
 
Posted: 29 June 2007 12:01 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  84
Joined  06-21-2007
ztinger - 29 June 2007 11:15 AM

can you post the code in your controller chisinau.php ?

here it is

<?php
class Chisinau extends Controller {
  function Chisinau()
  {
      $this->load->library(‘layout’, ‘layout_main’);
  }
 
  function index()
  {
      $this->layout->view(’/chisinau/index’, $data);   
      test();
  }
}
?>

 Signature 

everything about Moldova

Profile
 
 
Posted: 29 June 2007 06:14 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006

What is the function test() doing in your index() method? You are calling a function that doesn’t exist. You also have the variable $data being passed to $this->layout->view(’/chisinau/index’, $data); when you haven’t assigned anything to that variable.

Profile
 
 
Posted: 29 June 2007 11:58 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  84
Joined  06-21-2007

function test is in the helper which loads automaticaly…

I think data variable desn’t have anything common with this error

The problem is that I can’t load libraries

 Signature 

everything about Moldova

Profile
 
 
Posted: 30 June 2007 12:24 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006

and as the instructions say on the Wiki you have the Layout.php file located in your “/application/libraries/” folder?

Profile
 
 
Posted: 30 June 2007 12:32 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  84
Joined  06-21-2007

of course

I also tried to use uri class and get the same error
$product_id = $this->uri->segment(1);


Fatal error: Call to a member function on a non-object in /home/worldofm/public_html/apartments/system/application/controllers/chisinau.php on line 18

 Signature 

everything about Moldova

Profile
 
 
Posted: 30 June 2007 12:34 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006
emperius - 29 June 2007 11:58 PM

I think data variable desn’t have anything common with this error

That’s true, but it will cause an error once you get the other one fixed and it remains unassigned. Just pointing that out since I noticed it while looking through your controller code. smile

Profile
 
 
Posted: 30 June 2007 12:36 AM   [ Ignore ]   [ # 8 ]  
Grad Student
Rank
Total Posts:  84
Joined  06-21-2007
axle_foley00 - 30 June 2007 12:34 AM
emperius - 29 June 2007 11:58 PM

I think data variable desn’t have anything common with this error

That’s true, but it will cause an error once you get the other one fixed and it remains unassigned. Just pointing that out since I noticed it while looking through your controller code. smile

thank you wink

 Signature 

everything about Moldova

Profile
 
 
Posted: 30 June 2007 12:43 AM   [ Ignore ]   [ # 9 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006

Hmm…this is very strange. I’m currently using the exact same library on a project and it’s working perfectly. Your code looks fine to me also. (scratches head)

Profile
 
 
Posted: 30 June 2007 12:47 AM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  84
Joined  06-21-2007

Is there another way to get controller and view name?

I think somenthing doesn’t work :(

When I try to load any class i get this error…

 Signature 

everything about Moldova

Profile
 
 
Posted: 30 June 2007 12:55 AM   [ Ignore ]   [ # 11 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006
emperius - 30 June 2007 12:47 AM

Is there another way to get controller and view name?

What do you mean? There is of course the default way that CI loads views for controllers. Which is as follows:

$this->load->view('chisinau/index');

Or are you looking for another way?

emperius - 30 June 2007 12:47 AM

When I try to load any class i get this error…

Were you able to load your controllers before using the Layout Library?

Profile
 
 
Posted: 30 June 2007 01:01 AM   [ Ignore ]   [ # 12 ]  
Grad Student
Rank
Total Posts:  84
Joined  06-21-2007
axle_foley00 - 30 June 2007 12:55 AM
emperius - 30 June 2007 12:47 AM

Is there another way to get controller and view name?

What do you mean? There is of course the default way that CI loads views for controllers. Which is as follows:

$this->load->view('chisinau/index');

Or are you looking for another way?

emperius - 30 June 2007 12:47 AM

When I try to load any class i get this error…

Were you able to load your controllers before using the Layout Library?

I mean variables in uri name…

If I comment everything connected with layout library everything works fine.

But I can’t load default classes.

 Signature 

everything about Moldova

Profile
 
 
Posted: 30 June 2007 01:21 AM   [ Ignore ]   [ # 13 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1321
Joined  07-27-2006

You need to call parent::Controller() in the constructor

 Signature 

Check out the Template Library

Profile
 
 
Posted: 30 June 2007 01:37 AM   [ Ignore ]   [ # 14 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006

[quote author=“emperius”]I mean variables in uri name…

I’m sorry but I’m still not understanding exactly what you mean or are trying to accomplish. Could you give an example of what you are trying to do?

[quote author=“emperius”]But I can’t load default classes

Which default classes are you trying to load?

Profile
 
 
Posted: 30 June 2007 01:44 AM   [ Ignore ]   [ # 15 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006
Colin Williams - 30 June 2007 01:21 AM

You need to call parent::Controller() in the constructor

D’oh, but of course, how did I miss that one. Good eye there Colin.

Emperius, that’s a good point Colin raised. As it says in the documentation, if you have a constructor (ie. a function with the same name as the class or in PHP5 __construct() ) then you must have “parent::Controller() in it. So your controller will now look like this:

<?php
class Chisinau extends Controller {
  
function Chisinau()
  
{
    parent
::Controller(); // NOTE: This is necessary if you have a constructor, which the function Chisinau is.
    
$this->load->library('layout', 'layout_main');
  
}

  
function index()
  
{
    $this
->layout->view('/chisinau/index', $data);
    
test();
  
}
}
?>

Once again thanks for pointing that out Colin.

Does that solve your problem now Emperius?

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64455 Total Logged-in Users: 21
Total Topics: 80965 Total Anonymous Users: 1
Total Replies: 435699 Total Guests: 210
Total Posts: 516664    
Members ( View Memberlist )