Exemple #1
0
 public function testToAjax()
 {
     Yii::$app->request->baseUrl = '';
     Yii::$app->request->scriptUrl = '';
     $url = Url::toAjax('news/default/index', ['id' => 1, 'title' => 'foo-bar']);
     $this->assertEquals('/news/default/index?id=1&title=foo-bar', $url);
 }
Exemple #2
0
 public function testAjaxStaticHelper()
 {
     Yii::$app->request->baseUrl = '';
     $this->assertEquals('/de/not/exists/action', Url::toAjax('not/exists/action'));
     Yii::$app->composition->hidden = true;
     $this->assertEquals('/not/exists/action', Url::toAjax('not/exists/action'));
 }
Exemple #3
0
 public function actionIndex()
 {
     // redirect logged in users
     if (!Yii::$app->adminuser->isGuest) {
         return $this->redirect(['/admin/default/index']);
     }
     $this->view->registerJs("\$(function(){ \$('#email').focus(); observeLogin('#loginForm', '" . Url::toAjax('admin/login/async') . "', '" . Url::toAjax('admin/login/async-token') . "'); });", \luya\web\View::POS_END);
     return $this->render('index');
 }
 public function actionIndex()
 {
     $url = Url::base(true) . '/admin';
     // redirect logged in users
     if (!Yii::$app->adminuser->isGuest) {
         return $this->redirect($url);
     }
     // get the login form model
     $model = new \admin\models\LoginForm();
     // see if values are sent via post
     if (Yii::$app->request->post('login')) {
         $model->attributes = Yii::$app->request->post('login');
         if (($userObject = $model->login()) !== false) {
             if (Yii::$app->adminuser->login($userObject)) {
                 return $this->redirect($url);
             }
         }
     }
     $this->view->registerJs("\$(function(){ \$('#email').focus(); observeLogin('#loginForm', '" . Url::toAjax('admin/login/async') . "', '" . Url::toAjax('admin/login/async-token') . "'); });", \luya\web\View::POS_END);
     return $this->render('index', ['model' => $model]);
 }
Exemple #5
0
 /**
  * Return link for usage in ajax request, the link will call the defined callback inside
  * this block. All callback methods must start with `callback`. An example for a callback method:.
  * 
  * ```php
  * public function callbackTestAjax($arg1)
  * {
  *     return 'hello callback test ajax with argument: arg1 ' . $arg1;
  * }
  * ```
  * 
  * The above defined callback link can be created with the follow code:
  * 
  * ```php
  * $this->createAjaxLink('TestAjax', ['arg1' => 'My Value for Arg1']);
  * ```
  * 
  * The most convient way to assign the variable is via extraVars
  * 
  * ```php
  * public function extraVars()
  * {
  *     return [
  *         'ajaxLinkToTestAjax' => $this->createAjaxLink('TestAjax', ['arg1' => 'Value for Arg1']),
  *     ];
  * }
  * ```
  * 
  * @param string $callbackName The callback name in uppercamelcase to call. The method must exists in the block class.
  * @param array  $params       A list of parameters who have to match the argument list in the method.
  *
  * @return string
  */
 public function createAjaxLink($callbackName, array $params = [])
 {
     $params['callback'] = Inflector::camel2id($callbackName);
     $params['id'] = $this->getEnvOption('id', 0);
     return Url::toAjax('cms/block/index', $params);
 }