public function testUrlSegmentReturnsCorrectly() { $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = '/index.php'; // Default SERVER_PROTOCOL method to HTTP/1.1 $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['REQUEST_URI'] = '/user/index/2'; $this->assertNotNull(Url::segment('1')); $this->assertEquals('2', Url::segment('3')); }
<th>Price</th> <th>Created At</th> <th>Updated At</th> <th class="sorter-false">Action</th> </tr> </thead> <tbody> <?php if (count($records) > 0) { //$i = 1; if (Url::segment(2) == '' || Url::segment(3) == '' || Url::segment(3) == 1) { $i = 1; } else { $i = (Url::segment(3) - 1) * $records[0]->perPage + 1; } $rowType = null; foreach ($records as $key => $row) { $rowType = $i % 2 == 0 ? 'even' : 'odd'; ?> <tr class='<?php echo $rowType; ?> '> <td> <?php echo $i; ?> </td> <td><?php echo $row->product_name;
private function setCurrentPageUrl() { $controller = Url::segment(1); $method = ''; $method = Url::segment(2) == '' ? 'index' : Url::segment(2); $this->currentPageUrl = Url::getBase() . $controller . '/' . $method; }
/** * Update a product * * @param $id */ public function editAction($id) { $validator = null; $product = array(); $product = Product::find($id); $form = new ProductForm($product, Url::segment(3)); $form->action = 'edit'; $input = Input::make(); //Check is form posted if ($input->hasPost('btnSubmit') == true) { $validator = $this->setValidationRules($input); //Run validation if ($validator->run()) { // get post array value except the submit button $postArray = $input->except('btnSubmit')->post(); $product->product_name = $postArray["product_name"]; $product->category = $postArray["category"]; $product->description = $postArray["description"]; $product->validity = $postArray["validity"]; $product->price = $postArray["price"]; $product->created_at = $postArray["created_at"]; $product->updated_at = $postArray["updated_at"]; // Save form information if ($product->save()) { $this->setFlash('success', 'Product updated successfully!')->redirectTo('product/index/' . Url::segment(3)); } else { $this->setFlash('error', 'Error occured while updating Product!')->redirectTo('product/index/' . Url::segment(3)); } } else { //validation error here $form->errors = $validator->getErrors(); } $form->validation = $validator; } $this->render('update', array('form' => $form->buildForm()->render(), 'validation_errors' => $form->errors, 'title' => 'Update the Product')); }