Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

zf

No description
by

Carl Helmertz

on 16 April 2010

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of zf

ZF fshop.se/news/view/id/24 fshop.se/shop/category/id/ fshop.se/order/complain standard: fshop.se/controller/action/param-1/value-1/param-2/value-2/param-n/value-n

exempel: fshop.se/order/list-all/page/5/sort/asc NewsController extends Zend_Controller_Action {
viewAction() {
// request = GET & POST
$this->getRequest()->getParam('id');
// nu har du id:t, bara att hamta ratt nyhet
}
} /application/controllers/NewsController.php application/views/scripts/news/view.phtml NewsController extends Zend_Controller_Action {
viewAction() {
// getParam('id') == $_GET['id']
$news_id = $this->getRequest()->getParam('id');

// view == alla variabler som behovs i *.phtml-filen
$this->view->news = array('title' => 'Idag fyller Rex 151 ar!', 'content' => 'Rex forsta planer ar att fa prezi att stodja å, ä och ö. Lange leve utf8!')
}
} Planen...:

<!DOCTYPE html>
<html>
<head></head>
<body>
<div class="news_post">
<h1>Idag fyller Rex 151 ar!</h1>
<p>Rex forsta planer ar att fa prezi att stodja &aring;, &auml; och &ouml;. Lange leve utf8!</p>
</div>
</body>
</html> <!DOCTYPE html>
<html>
<head></head>
<body>
<div class="news_post">
<h1><?= $this->news['title'] ?></h1>
<p><?= $this->news['content'] ?></p>
</div>
</body>
</html> ZF:
/var/www/production/fshop/application
/var/www/production/fshop/library
/var/www/production/fshop/public
/var/www/production/fshop/public/index.php

Filer som traffas av server (lighttpds config) och alltid serveras
/var/www/production/fshop/public/old/FOREVER2/home.php
/var/www/production/fshop/public/old/index.php fshop.se/order/view/id/423 Visning av order ar uppdelad i MVC (model + view + controller). Lets go:

isolerad klass: OrderController
uppdrag: tolkar url -> hamtar data -> skicka data till view
fil:/application/controllers/OrderController.php

isolerad klass: Model_Order
uppdrag: hamtar data pa kommando. typisk funktion i "vanlig php"
fil:/application/models/Order.php
exempel?

... view?
klass: Zend_View
uppdrag: vara korkad, skriv ut data som den blir tillsagd. ingen makt (kommer du ihag nyhetsexemplet?
filer:
/application/views/scripts/order/index.phtml skinny controller, fat model class Model_Order {
public function getBetween($start, $end) {
// massvis med kod, men det ar bara bra:
// denna kod anvands i: admin, tavlingar, generell statistik, snabbstatistik, nyhetsmail, redovisning, min org...
// you name it.. andras databasstrukturen andrar man pa en plats: har. klart.
if(preg_match('/\d{4}-\d{2}-\d{2}/', $start) || preg_match('/\d{4}-\d{2}-\d{2}/', $end)) {
throw new Exception("Datum ar inte angivna i giltigt format (YYYY-mm-dd)");
}
if(strtotime($start) > time()) {
throw new Exception("Kan inte hamta framtida order!");
}
if(strtotime($start) > strtotime($end) {
throw new Exception("Kan inte hamta order angivna i fel ordning");
}

mysql_query(...);
return $orders;
}
public function getSunscreenCount($distid) {
mysql_query('select...');
return mysql_num_rows($sql);
}
} class OrderController {
public function between() {
// igen: url: fshop.se/order/between/start/2008/end/2009
// ta fram varden med minimal anstrangning
$this->view->start = $this->getRequest()->getParam('start');
$this->view->end = $this->getRequest()->getParam('end');

$model = new Model_Order();
$this->view->orders = $model->getOrdersBetween($this->getRequest()->getParam('start'), $this->getRequest()->getParam('end'));
}
public function sunscreenAction() {
// SKINNY! - latt att felsoka
// ansvar: tolka url: sunscreenAction tas fran fshop.se/order/sunscreen
// ansvar: ta fram varden: $model->getSunscreen()
// ansvar: skicka varden till tryckeri: $this->view->sunscreen_count
$model = new Model_Order();
$this->view->sunscreen_count = $model->getSunscreenCount(Flp_Distributor::getLoggedIn()->getId());
}
} // application/views/scripts/order/between.phtml
<p>Order lagda mellan <?= $this->start ?> och <?= $this->end ?>
<ul>
<?php foreach($this->orders as $order) { ?>
<li><?= $order['date'] ?></li>
<?php } ?>
</ul> // application/views/scripts/order/sunscreen.phtml

<?php if(0 == $this->sunscreen_count) { ?>
<p>Du har inte bestallt sunscreen.</p>
<?php }else{ ?>
<p>Hej. du har bestallt <?= $this->sunscreen_count ?> antal sunscreen, ge tillbaka!</p>
<?php }?>
Slides
Zend_Tool med mera: http://www.slideshare.net/bradley.holt/zend-framework-introduction
Modeller pa ett smart satt: http://www.slideshare.net/weierophinney/playdoh-modelling-your-objects-1766001

Två vettiga guider istället för officiella referensmanualen:
Survive the deep end: http://survivethedeepend.com/zendframeworkbook/en/1.0
Reference guide: http://www.mikaelkael.fr/doczf/1.10/en/
Full transcript