php - Cannot save POST items to database with Phalcon framework -
php - Cannot save POST items to database with Phalcon framework -
controller:
class peoplecontroller extends \phalcon\mvc\controller{ public function indexaction(){ } public function createpersonaction(){ $person = new people(); $person->firstname=$this->request->getpost("firstname"); $person->surname=$this->request->getpost("surname"); $person->telephone=$this->request->getpost("telephone"); $person->email=$this->request->getpost("email"); $person->city=$this->request->getpost("city"); $person->country=$this->request->getpost("country"); $person->save(); if ($person) { echo"successfully registered user!"; } else { echo "sorry, next problems generated: "; foreach ($person->getmessages() $message) { echo $message->getmessage(), "<br/>"; } } } }
model:
<?php class people extends \phalcon\mvc\model{ }
i have tried implementing getsource() method model phalcon docs suggest still not getting desired output of saving post items database
try this:
<?php utilize phalcon\mvc\controller phcontroller; class peoplecontroller extends phcontroller { public function indexaction() { //when no view(aka template) used should disable view rendering //otherwise output buffer can overwritten , echoes won't display $this->view->disable(); echo "<h1>index action!</h1>"; } public function createpersonaction() { $this->view->disable(); if($this->request->ispost()) { $datasent = $this->request->getpost(); $person = new people(); $person->firstname = $datasent["firstname"] $person->surname = $datasent["surname"]; $person->telephone = $datasent["telephone"]; $person->email = $datasent["email"]; $person->city = $datasent["city"]; $person->country = $datasent["country"]; $savedsuccessfully = $person->save(); if($savedsuccessfully) { echo "successfully registered user!"; } else { $messages = $person->getmessages(); echo "sorry, next problems generated: "; foreach ($messages $message) { echo "$message <br/>"; } } } else { echo "the request method should post!"; } } }
also, add together code main index.php (just before phalcon\mvc\application->handle()
):
$debug = new \phalcon\debug(); $debug->listen();
with you'll improve error messages, can check if db settings ok. remember phalcon works database schema passively, means, tables , fields should exist model stored, phalcon use tables , never create them.
php html phalcon
Comments
Post a Comment