Single Page Controller

Permalink
Hi

I'm doing my first single page controller - quite a noob so bear with me :)

"Call to a member function zxczxczxc() on a non-object"

Files:
\single_pages\indentity_verification\view.php
\controllers\indentity_verification\controller.php

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
class IdentityVerificationController extends Controller {
    public function on_start() {
        $hello = 'hello';
        $this->set('test', $hello);
    }
    public function zxczxczxc() {
        return 'hello';
    }
}
?>

<h1>Identity Verification</h1>
<?php
    #$controller->zxczxczxc();  works obviously if these two lines are uncommented
    #$controller = new IdentityVerificationController();
?>
<p><?php echo $controller->zxczxczxc(); ?></p>
<p><?php echo $contrller->test; ?></p>


I think I did something wrong or I'm missing something that is used to make a instance of my controller.

 
JohntheFish replied on at Permalink Reply
JohntheFish
Off the top of my head, try
$this->controller->zxc..etc..();


Your notes about the commented out lines - beware that it won't be the same instance of the controller as the one that you are working from the view of.
JohntheFish replied on at Permalink Reply
JohntheFish
On the second part, in the view you will have the the variable $test.
echo $test;
thrixxx replied on at Permalink Reply
echo $test;
$this->controller->zxczxczxc();

Tried it. Still doesn't work.

I'm pretty sure that my controller isn't loading. Do I need to specify anything in the view about the controller to use or vice versa?

Are my files in the correct folder/nameing structure?
JohntheFish replied on at Permalink Reply
JohntheFish
I expect this is what you tried, but just to be sure, what I meant was
echo $this->controller->zxc..etc..();


If your controller isn't loading, chances are there is an issue with the filename, classname or path not following the naming convention.

If it is not in a package and added by the package controller, you may also need to add it at /dashboard/pages/single/.

Personally, I always build single pages within packages.
JohntheFish replied on at Permalink Reply
JohntheFish
To check if your controller is loading, put a deliberate syntax error in the php and watch the site crash (or not).
thrixxx replied on at Permalink Reply 2 Attachments
Sorry! Yes that is what I tried.

I added an error and conrete did display a message for it.

Not so sure what you mean by the 'add it at /dashboard/pages/single/' ? This page is going to be used by the public, not dashboard.

I didn't build this in a package but if you think it's a better choice could you maybe link me to a article or example?

I attached the deliberate error and then the one I'm trying to fix :|
JohntheFish replied on at Permalink Reply
JohntheFish
/dashboard/pages/single/ is a dashboard page for managing single pages throughout your site, not just dashboard pages.