コード例 #1
0
 /**
  * Lists all items in the basket.
  * @attribute[RequestParam('error','string',false)]
  */
 function Index($error)
 {
     // display any given error message
     if ($error) {
         $this->content(uiMessage::Error($error));
     }
     // prepare basket variable
     if (!isset($_SESSION['basket'])) {
         $_SESSION['basket'] = array();
     }
     if (count($_SESSION['basket']) == 0) {
         $this->content(uiMessage::Hint('Basket is empty'));
     } else {
         // list all items in the basket ...
         $ds = model_datasource('system');
         $price_total = 0;
         foreach ($_SESSION['basket'] as $id => $amount) {
             $prod = $ds->Query('products')->eq('id', $id)->current();
             //... each using a template
             $this->content(Template::Make('product_basket'))->set('title', $prod->title)->set('amount', $amount)->set('price', $prod->price)->set('image', resFile($prod->image))->set('add', buildQuery('Basket', 'Add', array('id' => $prod->id)))->set('remove', buildQuery('Basket', 'Remove', array('id' => $prod->id)));
             $price_total += $amount * $prod->price;
         }
         // display total price and the button to go on
         $this->content("<div class='basket_total'>Total price: {$price_total}</div>");
         $this->content(uiButton::Make("Buy now"))->onclick = "location.href = '" . buildQuery('Basket', 'BuyNow') . "'";
     }
 }
コード例 #2
0
 /**
  * Lists all products.
  * @attribute[RequestParam('error','string',false)]
  */
 function Index($error)
 {
     // display error message if given
     if ($error) {
         $this->content(uiMessage::Error($error));
     }
     // loop thru the products...
     $ds = model_datasource('system');
     foreach ($ds->Query('products')->orderBy('title') as $prod) {
         //... and use a template to represent each
         $this->content(Template::Make('product_overview'))->set('title', $prod->title)->set('tagline', $prod->tagline)->set('image', resFile($prod->image))->set('link', buildQuery('Products', 'Details', array('id' => $prod->id)));
     }
 }
コード例 #3
0
ファイル: admin.class.php プロジェクト: Naveenr9/WebFramework
 /**
  * @attribute[RequestParam('username','string',false)]
  * @attribute[RequestParam('password','string',false)]
  */
 function Login($username, $password)
 {
     // if credentials are given, try to log in
     if ($username && $password) {
         // see config.php for credentials
         if ($username == cfg_get('admin', 'username') && $password == cfg_get('admin', 'password')) {
             $_SESSION['logged_in'] = true;
             // check only the fact that somebody logged in
             redirect('Admin');
         }
         $this->content(uiMessage::Error("Unknown username/passsword"));
     }
     // putting it together as control here. other ways would be to create a new class
     // derived from Control or a Template (anonymous or with an own class)
     $form = $this->content(new Form());
     $form->content("Username:"******"<br/>Password:"******"Login");
 }