Views embody the visual essence of your application.
Typically, they take the form of HTML files enriched with embedded PHP code, exclusively dedicated to tasks revolving around data presentation. Views take charge of furnishing data to the web browser or any other tool responsible for soliciting information from your application
Initialization
$this->view = new View($this->appConfig);
Has Methods
setJavascript: array setCss: array setTitle: string setDescription: string setKeywords: string setViewsDir: string getAppConfig: return object start: return void render: controller, view, level finish: return void getContent: return void setRenderLevel: parameter, content
The view class includes a translate class for creating translations based on a dictionary.
Example #1
public function indexAction() { $this->view->setTitle($this->view->t->_('String For Translations'); $this->view->setJavascript([ '/path/to/your/js/file.js', ]); $this->view->setCss([ '/path/to/your/css/file.css', ]); }
Example #2
public function indexAction() { $this->view->start(); $this->view->render('ModuleName', 'LayoutName', $this->view::LEVEL_MAIN_LAYOUT); $this->view->setRenderLevel($this->view::LEVEL_MAIN_LAYOUT, $this->view->getContent()); }
Example #3
public function Foo() { if(!in_array($this->di->dispatcher->getControllerName(), ['index'])) { $this->view->start(); $this->di->flash->error($this->view->translate->_('Error Message')); $this->di->response->redirect('/path/url/to/redirect'); $this->view->finish(); } }
Example #4
public function Foo() { $this->view->start(); if($this->di->request->getPost('foo') == false) { $response = ['array']; $this->di->response->setJsonContent($response)->send(); } OR \Components\Helper::toJson(true, $this->view->translate->_('MESSAGE')); $this->view->finish(); }
Initialize paramaters in controller and print it in view
in controller public function FooAction() { $this->view->foo = (new Model)->findFirst(int); } In view print_r($this->view->foo);