PHP 오픈 소스 개발 프레임워크 ZendFramework 사용 중 FAQ 설명 및 솔루션
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
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.