-1

I have this Controller in my pure php mvc cms :

class AdminController extends Controller
{
    /**
     * Construct this object by extending the basic Controller class
     */
    public function __construct()
    {
        parent::__construct();

        // special authentication check for the entire controller: Note the check-ADMIN-authentication!
        // All methods inside this controller are only accessible for admins (= users that have role type 7)
        Auth::checkAdminAuthentication();
    }

    /**
     * This method controls what happens when you move to /admin or /admin/index in your app.
     */
    public function index()
    {

        $this->View->render('admin/index','admin', array(
                'users' => UserModel::getPublicProfilesOfAllUsers(),

            )
        );

        $this->Language->load('error/not_found'); 

        $data['header'] = $this->Language->get('heading_title');   

        //echo $data['header'];


    }
}

In action when I echo $data['header']; My output is true and show my result. Now I need to Send This result to view template. in view I have:

<p><?php echo $header; ?></p>

But in result I see This error:

Notice: Undefined variable: header in /htdocs/cms/application/view/admin/index.php on line 59

Update: View Class:

class View
{

    /**
     * simply includes (=shows) the view. this is done from the controller. In the controller, you usually say
     * $this->view->render('help/index'); to show (in this example) the view index.php in the folder help.
     * Usually the Class and the method are the same like the view, but sometimes you need to show different views.
     * @param string $filename Path of the to-be-rendered view, usually folder/file(.php)
     * @param array $data Data to be used in the view
     */
    public function render($filename, $folder = null, $data = null)
    {
        if ($data) {
            foreach ($data as $key => $value) {
                $this->{$key} = $value;
            }
        }

        if($folder = 'admin'){

            require Config::get('PATH_VIEW_ADMIN') . '_templates/header.php';
            require Config::get('PATH_VIEW') . $filename . '.php';
            require Config::get('PATH_VIEW_ADMIN') . '_templates/footer.php';   

        } else {

            require Config::get('PATH_VIEW') . '_templates/header.php';
            require Config::get('PATH_VIEW') . $filename . '.php';
            require Config::get('PATH_VIEW') . '_templates/footer.php';

        }
    }

how do fix this error and send data to view template?

tereško
  • 58,060
  • 25
  • 98
  • 150
NewCod3r
  • 1,168
  • 1
  • 12
  • 28

1 Answers1

0

as i can see on your view class.

You have to modify your action method like this :

/**
 * This method controls what happens when you move to /admin or /admin/index in your app.
 */
public function index()
{
    $this->Language->load('error/not_found'); 

    $header = $this->Language->get('heading_title');   

    $this->View->render('admin/index','admin', array(
            'users' => UserModel::getPublicProfilesOfAllUsers(),
            'header' => $header
        )
    );
}

then on your view you can do :

<p><?php echo $this->header; ?></p>
<p><?php echo $data['header']; ?></p>

As you can see you have two options to access to your parameter bag on your html part.

Yanis-git
  • 7,737
  • 3
  • 24
  • 41