• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

undefined variable: viewParams

Matthew Hawley

Well-known member
I am getting this error when I go the route for my custom addon (/directory). I don't get why I am getting this error because a lot of addons use viewParams in the controller public file.

Server Error
Undefined variable: viewParams

  1. XenForo_Application::handlePhpError() in CF/Directory/ControllerPublic/Directory.php at line 10
  2. CF_Directory_ControllerPublic_Directory->actionIndex() in XenForo/FrontController.php at line 337
  3. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
  4. XenForo_FrontController->run() in /home3/mcwh/public_html/xxx/index.php at line 13
Here is my code for /ControllerPublic/Directory.php


class CF_Directory_ControllerPublic_Directory extends XenForo_ControllerPublic_Abstract

    public function actionIndex()

        // send to template for display
        return $this->responseView('CF_Directory_Index', 'cf_directory_index', $viewParams);



Chris D

XenForo developer
Staff member
I would recommend going through some basic PHP tutorials. There are some good ones. Code Academy and ... I think one's called Treehouse.

It would be wise to go through the basics.


Well-known member
Most of your errors have come from a lack of general PHP knowledge. It would be highly beneficial to learn the basics before attempting an addon.