Sunday, 15 April 2012

php - Sending a variable to the view which is used in controller with phalconPHP -



php - Sending a variable to the view which is used in controller with phalconPHP -

i have little issue have declared variable of type boolean in controller.

$done=false

now there trigger in controller turn true , @ point send corresponding view controller .. have used following.

$done=true; $this->view->setvar("done", $done);

now when seek phone call in corresponding view not know of varible.

if($done==true) { echo' <div class="alert alert-success"> <a href="addnewskill" class="alert-link">add here!</a> </div> '; }

it gives me following:

notice: undefined variable: done in >c:\xampp\htdocs\blueware\app\views\addnewskill\index.phtml on line 36

now there improve way of sending varible through view or making mistake?

full controller/action code:

<?php class addnewskillcontroller extends \phalcon\mvc\controller{ public function indexaction(){ } public function confirmaction(){ $this->view->disable(); $done=false; if($this->request->ispost()) { $datasent = $this->request->getpost(); $skill = new skills(); $skill->technology = $datasent["technology"]; $skill->skillname = $datasent["skillname"]; $skill->description = $datasent["description"]; $savedsuccessfully = $skill->save(); if($savedsuccessfully) { $done=true; $this->view->setvar("done", $done); } else { $messages = $skill->getmessages(); echo "sorry, next problems generated: "; foreach ($messages $message) { echo "$message <br/>"; } } } else { echo "the request method should post!"; } } }

full view code:

<?php if($done==true) { echo' <div class="alert alert-success"> <a href="addnewskill" class="alert-link">add here!</a> </div> '; } ?>

if($savedsuccessfully) { $done=true; $this->view->setvar("done", $done); } else {

you should setting variable there, setting in view after seems not saving , hence not passing variable on

similar

if($savedsuccessfully) { $done=true; } else { ...later in code ... $this->view->setvar("done", $done);

or just

$this->view->setvar("done", $savedsuccessfully);

php html phalcon

No comments:

Post a Comment