private function setTwigBaseUrl() { // We will set baseUrl as default function to twig engine $this->functions[] = $this->getTwigSimpleFunctionInstance('baseUrl', function () { return Url::getBase(); }); return $this; }
public function testDivOrSpanElementForFormBuilder() { $this->setUpAssetConfig(); $form = Form::make()->open('contact', ['method' => 'post', 'action' => Url::sitePath('contact/add'), 'role' => 'form', 'style' => 'width:500px;margin-top:35px;float:left;'])->addElement('openTag', 'div_1', ['style' => 'border:1px solid red;height:40px;'])->addElement('text', 'I am Inside Div 1', ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement('closeTag', 'div_1')->addElement('openTag', 'div_2', ['style' => 'border:1px solid red;height:40px;'])->addElement('text', 'I am Inside Div 2', ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement('closeTag', 'div_2')->createForm()->close(); $formString = preg_replace("/\r\n|\r|\n|\t/", '', trim("<form name='contact' method='post' action='http://localhost/cygnite/contact/add' role='form' style='width:500px;margin-top:35px;float:left;' >\n\t\t\t<div name='div_1_1331' style='border:1px solid red;height:40px;' />\n\t\t\t<input name='I am Inside Div 1' class='col-sm-2 control-label' style='width:100%;' type='text' />\n\t\t\t</div>\n\t\t\t<div name='div_2_1224' style='border:1px solid red;height:40px;' />\n\t\t\t<input name='I am Inside Div 2' class='col-sm-2 control-label' style='width:100%;' type='text' />\n\t\t\t</div>\n\t\t\t</form>")); // It works though But we cannot Test it because it generate random name for Div or Span Element // For Example [name='div_2_1224' or name='div_1_1331'] }
public function setUp() { $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['REQUEST_URI'] = '/'; $app = Application::instance(); $app['router'] = new Router(); Url::setBase("/cygnite/index.php/user"); }
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')); }
private function setUpAssetConfig() { $app = Application::instance(); $app['router'] = new \Cygnite\Base\Router\Router(); $_SERVER['REQUEST_URI'] = '/hello/user'; $_SERVER['HTTP_HOST'] = 'localhost'; $configuration = ['global.config' => ['encoding' => 'utf-8']]; Config::$config = $configuration; Url::setBase('/cygnite/'); //$app['router']->getBaseUrl() }
/** * Build form and return object * @return ProductForm */ public function buildForm() { $id = isset($this->model->id) ? $this->model->id : ''; // Below code is to display validation errors below the input box if (is_object($this->validator)) { // Set your custom errors //$this->validator->setCustomError('column.error', 'Your Custom Error Message'); } $this->open("Product", ["method" => "post", "id" => "uniform", "role" => "form", "action" => Url::sitePath("product/{$this->action}/{$id}/"), "style" => "width:500px;margin-top:35px;float:left;"])->addElement("label", "Product Name", ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement("text", "product_name", ["value" => isset($this->model->product_name) ? $this->model->product_name : "", "class" => "form-control"])->addElement("label", "Category", ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement("text", "category", ["value" => isset($this->model->category) ? $this->model->category : "", "class" => "form-control"])->addElement("label", "Description", ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement("text", "description", ["value" => isset($this->model->description) ? $this->model->description : "", "class" => "form-control"])->addElement("label", "Validity", ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement("text", "validity", ["value" => isset($this->model->validity) ? $this->model->validity : "", "class" => "form-control"])->addElement("label", "Price", ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement("text", "price", ["value" => isset($this->model->price) ? $this->model->price : "", "class" => "form-control"])->addElement("label", "Created At", ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement("text", "created_at", ["value" => isset($this->model->created_at) ? $this->model->created_at : "", "class" => "form-control"])->addElement("label", "Updated At", ["class" => "col-sm-2 control-label", "style" => "width:100%;"])->addElement("text", "updated_at", ["value" => isset($this->model->updated_at) ? $this->model->updated_at : "", "class" => "form-control"])->addElement("submit", "btnSubmit", ["value" => "Save", "class" => "btn btn-primary", "style" => "margin-top:15px;"])->close()->createForm(); return $this; }
private function setUpAssetConfig() { $loader = m::mock("Cygnite\\Foundation\\Autoloader"); $app = Application::getInstance($loader); $app['router'] = m::mock("Cygnite\\Base\\Router\\Router"); $_SERVER['REQUEST_URI'] = '/hello/user'; $_SERVER['HTTP_HOST'] = 'localhost'; $configuration = ['global.config' => ['encoding' => 'utf-8']]; Config::$config = $configuration; Url::setBase('/cygnite/'); //$app['router']->getBaseUrl() }
/** * Build form and return object * @return CommentForm */ public function buildForm() { $id = isset($this->model->id) ? $this->model->id : ''; // Fllowing code is to display validation errors below the input box if (is_object($this->validation)) { $this->validator = $this->validation; // Errors will displayed below to inputs // Set your custom errors //$this->validator->setCustomError('column_name_error', 'Custom Error'); } $this->open("CommentController", array("method" => "post", "id" => "uniform", "role" => "form", "action" => Url::sitePath("comment/type/{$id}/{$this->segment}"), "style" => "width:500px;margin-top:35px;float:left;"))->addElement("label", "P Id", array("class" => "col-sm-2 control-label", "style" => "width:100%;"))->addElement("text", "p_id", array("value" => isset($this->model->p_id) ? $this->model->p_id : "", "class" => "form-control"))->addElement("label", "F Name", array("class" => "col-sm-2 control-label", "style" => "width:100%;"))->addElement("text", "f_name", array("value" => isset($this->model->f_name) ? $this->model->f_name : "", "class" => "form-control"))->addElement("label", "Post", array("class" => "col-sm-2 control-label", "style" => "width:100%;"))->addElement("text", "post", array("value" => isset($this->model->post) ? $this->model->post : "", "class" => "form-control"))->addElement("label", "F Image", array("class" => "col-sm-2 control-label", "style" => "width:100%;"))->addElement("text", "f_image", array("value" => isset($this->model->f_image) ? $this->model->f_image : "", "class" => "form-control"))->addElement("label", "Date Created", array("class" => "col-sm-2 control-label", "style" => "width:100%;"))->addElement("text", "date_created", array("value" => isset($this->model->date_created) ? $this->model->date_created : "", "class" => "form-control"))->addElement("label", "Userip", array("class" => "col-sm-2 control-label", "style" => "width:100%;"))->addElement("text", "userip", array("value" => isset($this->model->userip) ? $this->model->userip : "", "class" => "form-control"))->addElement("submit", "btnSubmit", array("value" => "Save", "class" => "btn btn-primary", "style" => "margin-top:15px;"))->close()->createForm(); return $this; }
private function setUpAssetConfig() { $app = Application::instance(); $app['url'] = new \Cygnite\Common\UrlManager\Url(); $app['request'] = \Cygnite\Http\Requests\Request::createFromGlobals(); $app['router'] = new \Cygnite\Base\Router\Router($app['request']); $app['url']->setApplication($app); $app['request']->server->add('REQUEST_URI', '/hello/user'); $app['request']->server->add('HTTP_HOST', 'localhost'); $configuration = ['global.config' => ['encoding' => 'utf-8']]; Config::$config = $configuration; Url::setBase('cygnite/'); //$app['router']->getBaseUrl() }
public function setUp() { $this->app = Application::instance(); $this->app['url'] = new \Cygnite\Common\UrlManager\Url(); $this->app['request'] = \Cygnite\Http\Requests\Request::createFromGlobals(); $this->app['router'] = new \Cygnite\Base\Router\Router($this->app['request']); $this->app['router']->setApplication($this->app); $this->app['url']->setApplication($this->app); $this->app['request']->server->add('HTTP_HOST', 'localhost'); $this->app['request']->server->add('REQUEST_URI', '/'); /* $app = Application::instance(); $app['router'] = new Router;*/ Url::setBase('/cygnite/index.php/user'); }
/** * Start booting and handler all user request * @return Dispatcher */ public function boot() { Url::instance($this['router']); //Set up configurations for your awesome application Config::set('config.items', $this['config']); //Set URL base path. Url::setBase(Config::get('global.config', 'base_path') == '' ? $this['router']->getBaseUrl() : Config::get('global.config', 'base_path')); //initialize framework $this['boot']->initialize(); $this['boot']->terminate(); /**------------------------------------------------------- * Booting completed. Lets handle user request!! * Lets Go !! * ------------------------------------------------------- */ return new Dispatcher($this['router']); }
/** * Start booting and handler all user request * * @return Dispatcher */ public function boot() { //Set up configurations for your awesome application Config::set('config.items', $this['config']); //Set URL base path. Url::setBase(Config::get('global.config', 'base_path') == '' ? $this['router']->getBaseUrl() : Config::get('global.config', 'base_path')); $this['service.provider'](); //initialize framework $this['boot']->initialize($this); $this['boot']->terminate(); return $this; }
/** * Generate anchor link * * @false string $url * @false string $name * @false array $attributes * @param $url * @param null $name * @param array $attributes * @return string */ protected function link($url, $name = null, $attributes = array()) { $name = is_null($name) ? $url : $name; list(, $caller) = debug_backtrace(false); if ($this->isFacade($caller)) { return $this->stripCarriage('<a href="' . Url::getBase() . Html::entities($url) . '" ' . $this->addAttributes($attributes) . '>' . Html::entities($name) . '</a>' . PHP_EOL); } $this->assets[strtolower(__FUNCTION__)][] = '<a href="' . Url::getBase() . Html::entities($url) . '" ' . $this->addAttributes($attributes) . '>' . Html::entities($name) . '</a>' . PHP_EOL; return $this->assets[strtolower(__FUNCTION__)]; }
/** * @param $method * @param $args * @return mixed|string * @throws \InvalidArgumentException */ public static function __callStatic($method, $args = array()) { $arguments = array('method' => $method, 'args' => $args, 'instance' => Url::make()); return call_user_func_array(array(Url::make(), 'call'), array($arguments)); }
/** * 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')); }
/** * We will destroy current user session and return to * application base url */ public function logout($redirect = true) { Session::delete(); $redirect ? Url::redirectTo(Url::getBase()) : ''; }
private function setCurrentPageUrl() { $controller = Url::segment(1); $method = ''; $method = Url::segment(2) == '' ? 'index' : Url::segment(2); $this->currentPageUrl = Url::getBase() . $controller . '/' . $method; }
/** * @param $method * @param $args * @return mixed|string * @throws \InvalidArgumentException */ public static function __callStatic($method, $args = []) { $arguments = ['method' => $method, 'args' => $args, 'instance' => Url::make()]; return call_user_func_array([Url::make(), 'call'], [$arguments]); }
/** * This Function is to get the url sitePath with index.php * * @access public * @false $uri * @param $uri * @return string */ public static function sitePath($uri) { $expression = array_filter(explode('/', $_SERVER['REQUEST_URI'])); $index = false !== array_search('index.php', $expression) ? 'index.php/' : ''; return Url::getBase() . $index . $uri; }
<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;
/** * @param string $uri * @param string $type * @param int $httpResponseCode * * @return $this */ protected function redirectTo($uri = '', $type = 'location', $httpResponseCode = 302) { Url::redirectTo($uri, $type, $httpResponseCode); return $this; }
.clear-fix{ height:2em;} a, a:visited {color:#2972A3;} a:hover {color:#72ADD4;} hr {display: block;border: 0; border-top: 1px solid #ccc; } </style> </head> <body> <?php use Cygnite\Common\UrlManager\Url; ?> <div class="wrapper"> <div class="clear-fix"></div> <div role="main" class="content"> <h1>Service Unavailable: 503 (Service Temporarily Unavailable)</h1> <hr> <p> We're sorry! Cannot process your request now. Server is down for maintenance. Please try again later. </p> <p> Please go to our <a href="<?php echo Url::getBase(); ?> ">home page</a>. </p> </div> </div> </body> </html>
/** * We will set the script into assets array. * * @param $src * @param $attributes */ private function setScript($src, $attributes) { $this->assets[$this->tag[$this->where]][strtolower(__FUNCTION__)][] = (string) static::$script . ' src="' . Url::getBase() . $src . '"' . $this->addAttributes($attributes) . '></script>' . PHP_EOL; }
<?php use Cygnite\Common\UrlManager\Url; use Cygnite\Helpers\Config; define('APP', str_replace('src/', 'src' . DS, APPPATH)); //Set URL base path. Url::setBase(Config::get('global.config', 'base_path') == '' ? $app['router']->getBaseUrl() : Config::get('global.config', 'base_path')); /* * -------------------------------------------------- * Set application encryption key * --------------------------------------------------- */ if (!is_null(Config::get('global.config', 'encryption.key'))) { define('CF_ENCRYPT_KEY', Config::get('global.config', 'encryption.key')); } /* * ---------------------------------------------------- * Throw Exception is default controller * has not been set in configuration * ---------------------------------------------------- */ if (is_null(Config::get('global.config', 'default.controller'))) { throw new \Exception('You must set default controller in ' . APPPATH . '/Configs/application.php'); }
/** * Build form and return object * @return Registration */ public function buildForm() { $id = isset($this->model->id) ? $this->model->id : ''; $this->open('users', array('method' => 'post', 'action' => Url::sitePath('products/type/' . $id . '/' . $this->segment), 'role' => 'form', 'style' => 'width:500px;margin-top:35px;float:left;'))->addElement('label', 'Product Type', array('class' => 'col-sm-2 control-label', 'style' => 'width:37.667%;'))->addElement('text', 'product_type', array('value' => isset($this->model->product_type) ? $this->model->product_type : '', 'class' => 'form-control'))->addElement('label', 'Name', array('class' => 'col-sm-2 control-label'))->addElement('text', 'name', array('value' => isset($this->model->name) ? $this->model->name : '', 'class' => 'form-control'))->addElement('label', 'Price', array('class' => 'col-sm-2 control-label'))->addElement('text', 'price', array('value' => isset($this->model->price) ? $this->model->price : '', 'class' => 'form-control'))->addElement('submit', 'btnSubmit', array('value' => 'Save', 'class' => 'btn btn-primary', 'style' => 'margin-top:15px;'))->close()->createForm(); return $this; }