PHP 오픈 소스 개발 프레임워크 ZendFramework 사용 중 FAQ 설명 및 솔루션

4696 단어
MVC 코드 작성: 컨트롤러 코드 작성:
 
  
class IndexController extends Zend_Controller_Action
{
function init()
{
$this->registry = Zend_Registry::getInstance();
$this->view = $this->registry['view'];
$this->view->baseUrl = $this->_request->getBaseUrl();

}
function indexAction()
{
$this->view->word=" I love spurs";

echo $this->view->render("index.html");

}
function addAction(){
// POST . .


}
}
?>


제어에 쓰기:
 
  
$this->view->word="ggg";
$this->view->render("index.html");
---->index.html echo $this->word;

application->config.ini
[general]
db.adapter=PDO_MYSQL
db.config.host=localhost
db.config.username=root
db.config.password=
db.config.dbname=think_zw


프로필을 프레임워크에 도입합니다
 
  
// ,
$config=new Zend_Config_Ini('./application/config/config.ini',null, true);
Zend_Registry::set('config',$config);
$dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());
$dbAdapter->query('SET NAMES UTF8');
Zend_Db_Table::setDefaultAdapter($dbAdapter);
Zend_Registry::set('dbAdapter',$dbAdapter);

단일 입구 모드:localhost/index/add/index 모듈에 접근하는dd 방법 function addaction () {} (Index Controller.php) 기본적으로 index 모듈에 접근하는 index 방법
모듈 모델의 메시지를 다시 만듭니다.php
 
  
class Message extends Zend_Db_Table
{
protected $_name ="message";
protected $_primary = 'id';
}
?>

모듈 인스턴스화:
 
  
function indexAction()
{
$message=new message();//

//
$this->view->messages=$message->fetchAll()->toArray();

echo $this->view->render('index.phtml');//
}

messages as $message): ?>







************** 데이터 수정 및 삭제
 
  

kk

ll


index.phtml에
 
  
편집자
삭제

새 방법 추가:edit.phtml
 
  
function editAction(){

$message = new Message();
$db = $message->getAdapter();

if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
$id = $this->_request->getPost('id');
$cid = $this->_request->getPost('cid');
$title = $this->_request->getPost('title');

$set = array(
'cid'=>$cid,
'title'=>$title
);
$where = $db->quoteInto('id = ?',$id);
//
$message->update($set,$where);
unset($set);
echo ' !되돌아오다';
}else{
$id = $this->_request->getParam('id');
$this->view->messages = $message->fetchAll('id='.$id)->toArray();
echo $this->view->render('edit.phtml');
}
}


function delAction(){
$message = new Message();
$id = (int)$this->_request->getParam('id');

if($id > 0){
$where = 'id = ' . $id;
$message->delete($where);
}
echo ' !되돌아오다';
}


예외가 발생했습니다.
 
  
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (index.php)' in

해결 방법: index.php의
 
  
$frontController =Zend_Controller_Front::getInstance();
$frontController->setParam('useDefaultControllerAlways', true);

*******id/3은 이전의 것입니까?id=3

좋은 웹페이지 즐겨찾기