php - Reload current page and upload a persistent variable in Phalcon -
all view in current project extend general index view looks this:
<!doctype html> <html> <head> <title>title</title> </head> {{ stylesheet_link("css/base.css") }} {{ stylesheet_link("css/layout.css") }} {{ stylesheet_link("css/skeleton.css") }} {{ stylesheet_link("css/main.css") }} {{ stylesheet }} <body> <div class="container"> <div class="one columns"> <!-- here nav-bar --> </div> <div class="sixteen columns"> <hr /> </div> <div class="one column offset-by-thirteen"><a href="#">{{ english }}</a></div> <div class="one column"><a href="#">{{ french }}</a></div> <div class="one column"><a href="#">{{ chinese }}</a></div> </div> {{ content() }} </body> </html>
so general index providing navigation bar , 3 links (english, french, chinese).
the controller looks following:
<?php use phalcon\mvc\controller; class controllerbase extends controller { protected function beforeexecuteroute($dispatcher) { $default_language = "en"; if (!isset($this->persistent->lang)) { $this->persistent->lang = $default_language; } // providing data here such pictures } protected function afterexecuteroute($dispatcher) { $this->view->url = $this->dispatcher->getcontrollername() . "/" . $this->dispatcher->getactionname() . "/" . $this->dispatcher->getparams(); } }
in protected function try current url.
my goal able change language reloading current url , updating persistent variable:
$this->persistent->lang
(so providing parameter while reloading page example), don't want load home page current page.
in provided code, trying desired url calling:
$this->dispatcher->getcontrollername() . "/" . $this->dispatcher->getactionname() . "/" . $this->dispatcher->getparams();
but getparams()
give me empty array...
for instance, have controller aboutcontroller
, have following action:
resumeaction($author)
so url page is:
http://localhost/website/about/resume/bob
but variable url
defined in basecontroller
give me about/resume/array
, not about/resume/bob
.
how desired path?
but variable
url
defined inbasecontroller
give meabout/resume/array
, notabout/resume/bob
.
when see array
show means variable array & should access such. $this->dispatcher->getparams()
function returns array. need act on it. can check it’s contents this:
echo '<pre>'; print_r($this->dispatcher->getparams()); echo '</pre>';
and can view additional data doing this:
echo '<pre>'; print_r($this->dispatcher->getparam('[name of param here]')); echo '</pre>';
and change [name of param here]
actual name of parameter access.
more details on getting parameters on the official phalcon documentation.
Comments
Post a Comment