Welcome Guest, Not a member yet? Register   Sign In
Can't load a controller from a view, why?
#1

[eluser]gusst250[/eluser]
In one 'view' I want to include a 'controller' (which should be able to load new views itself).

I use the command:
Code:
$url = base_url();
$url .= "application/controllers/content.php";
include $url;
to do it.

I get this error message:
Fatal error: Class content: Cannot inherit from undefined class controller in /var/www/02/22/69/bestallarkompetens.com/www/application/controllers/content.php on line 3

the first 5 lines of content.php is:
Code:
<?php
echo '<br/>content<br/>';        //just to verify that the previous include worked
class Content extends Controller
{
    function __construct()

content.php works fine when browsing to it manually, it's just when it is included in a view that this message appears.

Thankful for any help!

/Gustav
#2

[eluser]Thorpe Obazee[/eluser]
Controllers are meant to be the receiver of requests.

You could:

1. load the view file from the view or controller
2. use ajax to request
#3

[eluser]gusst250[/eluser]
ok, so how do I do it?

This 'include' is meant to include content.php in a <div> at the page, to make the site dynamic.
I would then be able to load views right in to that <div>.
#4

[eluser]Thorpe Obazee[/eluser]
[quote author="bargainph" date="1258267860"]Controllers are meant to be the receiver of requests.

You could:

1. load the view file from the view or controller
2. use ajax to request[/quote]

Points to previous answer------^

Or you could use a template library

Colin's template

Or you could use widgets.. see

Widgets
#5

[eluser]gusst250[/eluser]
Sorry, didn't see those links.. (stupid me), thanks anyway.
Will investigate possibilities!
#6

[eluser]gusst250[/eluser]
Ok, solved this particular situation with a system of templates.

But I'm interested in how to implement these jQuery/ajax-requests into codeIgniter's $this->load-thing.

What is the corresponding jQuery/ajax-syntax, in a controller, of loading a view with:
Quote:$this->load->view('somefile');
#7

[eluser]Thorpe Obazee[/eluser]
Well there's none at the moment. It would via normal jQuery..

Hmm.. one moment..
Code:
<div id="container">
   <div id="sidebar">
   </div>
    <div id="main">
        <a id="trigger" href="blah.html">Click me</a>
    </div>
</div>
&lt;script&gt;
$(function(){
   $('#trigger').click(function(){
      $('#sidebar).load("&lt;?php echo site_url('controller/method');?&gt;");
   });
});
&lt;/script&gt;


Something like that but of course you can pass along data on trigger etc.
Code:
// controller

function method()
{
    if (is_ajax())
    {
        echo "I'm the sidebar content";
    }
}
#8

[eluser]gusst250[/eluser]
Can't really try it now because I'm surfing on my iPod.
But it looks like exactly what i was looking for, thanksSmile




Theme © iAndrew 2016 - Forum software by © MyBB