مرسي واسه جواب!
ببين اين مدل من واسه يه جدول هست!
<?php
class Model_Bug extends Zend_Db_Table_Abstract
{
protected $_name = 'bugs';
public function createBug($name, $email, $date, $url, $description, $priority, $status)
{
// create new row in the bugs table
$row = $this->createRow();
//set the row data
$row->author = $name;
$row->email = $email;
$dateObject = new Zend_Date($date);
$row->date = $dateObject->get(Zend_Date::TIMESTAMP);
$row->url = $url;
$row->description = $description;
$row->priority = $priority;
$row->status = $status;
//save the new row
$row->save();
// now fetch the id of the row you just created and return it
$id = $this->_db->lastInsertId();
return $id;
}
و اين هم كنترل من واسه ذخيره:
<?php
class BugController extends Zend_Controller_Action
{
public function submitAction ()
{
$bugReportForm = new Form_BugReportForm();
$bugReportForm->setAction('/bug/submit');
$bugReportForm->setMethod('post');
if ($this->getRequest()->isPost()) {
if ($bugReportForm->isValid($_POST)) {
$bugModel = new Model_Bug();
// if the form is valid then create the new bug
$result = $bugModel->createBug(
$bugReportForm->getValue('author'),
$bugReportForm->getValue('email'),
$bugReportForm->getValue('date'),
$bugReportForm->getValue('url'),
$bugReportForm->getValue('description'),
$bugReportForm->getValue('priority'),
$bugReportForm->getValue('status'));
// if the createBug method returns a result
// then the bug was successfully created
if ($result) {
$this->_forward('confirm');
}
}
}
$this->view->form = $bugReportForm;
}
خب بعد از اجرا شدن كنترلر submit در آخر باس از شرط بگذره كه اگه موفقيت آميز بود به كنترل confirm منتقل ميشه!
ولي در صورتي كه اين اتفاق نميفته و همچنان در كنترلر submit ميمونم يعني result$ موفقيت آميز نبوده!!
اصلا من درست استفاده كردم ؟
كلا وقتي تنظيمات ديتابيس رو توي application.ini ست ميكنيم به چه شكل باس استفاده كرد؟
مرسي