Example #1
0
 /**
  * Restore to current locale if applicable.
  *
  * @return void
  */
 protected function restoreLocale()
 {
     $primaryLocale = $this->getPrimaryLocale();
     if ($primaryLocale && $primaryLocale !== $this->locale) {
         I18n::locale($this->locale);
     }
 }
Example #2
0
 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     $session = $this->request->session();
     $lang = 'en';
     if (isset($this->request->params['lang'])) {
         $lang = $this->request->params['lang'];
     } else {
         if ($session->check('Config.language')) {
             $lang = $session->read('Config.language');
         }
     }
     $session->write('Config.language', $lang);
     // Change current language by post request
     if ($this->request->is('post') && isset($this->request->data['language'])) {
         $newLang = $this->request->data['language'];
         $transUrl = $this->translateUrl($newLang);
         $this->redirect($transUrl);
     }
     $this->set('lang', $lang);
     $this->set('controller', $this->name);
     I18n::locale($lang);
     Time::setToStringFormat('YYYY-MM-dd HH:mm:ss');
     Type::build('datetime')->useLocaleParser();
     $this->Auth->config(['unauthorizedRedirect' => false]);
     $this->Auth->allow(['login', 'init']);
     $user = $this->Auth->user();
     if (isset($user)) {
         $username = $user['username'];
         $this->set(['is_authorized' => true, 'username' => $username]);
     } else {
         $this->set('is_authorized', false);
     }
 }
 public function getDateLocale()
 {
     $options = [];
     $defaultLocale = I18n::locale();
     $defaultLocale = isset($defaultLocale) ? $defaultLocale : 'en';
     $defaultLocale = strtolower($defaultLocale);
     $defaultLocale = str_replace('-', '_', $defaultLocale);
     switch ($defaultLocale) {
         case 'fr':
         case 'fr_fr':
             echo $this->AlaxosHtml->script('Alaxos.bootstrap/datepicker/locales/bootstrap-datepicker.fr.min', ['block' => true]);
             $options['language'] = 'fr';
             $options['alaxos_js_format'] = 'd/m/y';
             //format for Alaxos JS date parsing
             $options['datepicker_format'] = 'dd/mm/yyyy';
             $options['php_date_format'] = 'd/m/Y';
             break;
         case 'fr_ch':
             echo $this->AlaxosHtml->script('Alaxos.bootstrap/datepicker/locales/bootstrap-datepicker.fr-CH.min', ['block' => true]);
             $options['language'] = 'fr';
             $options['alaxos_js_format'] = 'd.m.y';
             //format for Alaxos JS date parsing
             $options['datepicker_format'] = 'dd.mm.yyyy';
             $options['php_date_format'] = 'd.m.Y';
             break;
         default:
             $options['language'] = 'en';
             $options['alaxos_js_format'] = 'y/m/d';
             //format for Alaxos JS date parsing
             $options['datepicker_format'] = 'yyyy/mm/dd';
             $options['php_date_format'] = 'Y/m/d';
             break;
     }
     return $options;
 }
Example #4
0
 public function beforeFilter(Event $event)
 {
     $permissions_file = json_decode(file_get_contents(DS . CONFIG . DS . 'permissions.json'));
     // set controller shared variables
     $this->permission = $permissions_file;
     $this->active_user = $this->Auth->user();
     // admin section
     if (isset($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin') {
         if ($this->request->params['controller'] == 'Users' && $this->request->params['action'] == 'add') {
             $this->Auth->allow();
         } else {
             $this->Auth->deny();
         }
     } else {
         $this->Auth->allow($this->request['action']);
     }
     // Use this across app views for admin only parts
     $this->set('active_user', $this->Auth->user());
     $this->set('permission', $permissions_file);
     // load posts and check for unapproved posts to add them into notifications
     $this->loadModel('Posts');
     $not_approved_posts = $this->Posts->find('all')->where(['approved' => false])->toArray();
     // set all notifications into this view variable
     $this->set('notifications', [$not_approved_posts]);
     // read session lang var and set app lang var
     $session = $this->request->session();
     if ($session->read('language')) {
         I18n::locale($session->read('language'));
     }
 }
 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     $this->layout = 'sl';
     $this->loadComponent('Paginator');
     $this->Auth->allow(array('view', 'index'));
     $this->set('homepage_title', __('Homepage Title'));
     $this->loadModel('BlogCategories');
     $this->set('asideBlogCategories', $this->BlogCategories->find('all', array('conditions' => array('enable' => true), 'recursive' => -1))->toArray());
     $this->loadModel('Tags');
     $this->set('asideTags', $this->Tags->find('all', array('conditions' => array('not' => array('taggings_count' => 0)), 'order' => array('taggings_count desc'), 'recursive' => -1))->toArray());
     $session = $this->request->session();
     $this->set('session', $session);
     /*
     if($session->check('theme')) {
     $this->theme=$session->read('theme');
     } else {
     $this->theme=null;
     }
     */
     if ($session->check('Config.language')) {
         I18n::locale($session->read('Config.language'));
     } else {
         I18n::locale($session->read('ko_KR'));
     }
 }
Example #6
0
 /**
  * Test language - empty
  *
  * @return void
  */
 public function testLangEmpty()
 {
     $expected = I18n::locale();
     $this->get('/pages/home');
     $actual = I18n::locale();
     $this->assertEquals($expected, $actual);
 }
    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $locale = isset($data['locale']) ? $data['locale'] : I18n::locale();
        $timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget');
        $timestamp = null;
        $timezoneOffset = null;
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTimeInterface && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            if ($timezoneAware) {
                $timestamp = $val->format('U');
                $dateTimeZone = new DateTimeZone(date_default_timezone_get());
                $timezoneOffset = $dateTimeZone->getOffset($val) / 60;
            }
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
html;
        if ($timezoneAware && isset($timestamp, $timezoneOffset)) {
            $widget .= <<<html
                    data-timestamp="{$timestamp}"
                    data-timezone-offset="{$timezoneOffset}"
html;
        }
        $widget .= <<<html
                    {$required}
                    {$disabled}
                />
                <label for="{$id}" class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </label>
            </div>
html;
        return $widget;
    }
Example #8
0
 /**
  * Retrieves information for current language.
  *
  * Useful when you need to read current language's code, language's direction,
  * etc. It will returns all the information if no `$key` is given.
  *
  * ### Usage:
  *
  * ```php
  * language('code');
  * // may return: en
  *
  * language();
  * // may return:
  * [
  *     'name' => 'English (US)',
  *     'locale' => 'en_US',
  *     'code' => 'en',
  *     'country' => 'US',
  *     'direction' => 'ltr',
  *     'icon' => 'us.gif',
  * ]
  * ```
  *
  * Accepted keys are:
  *
  * - `name`: Language's name, e.g. `English`, `Spanish`, etc.
  * - `locale`: Full localized language's code, e.g. `en-US`, `es`, etc.
  * - `code`: Language's ISO 639-1 code, e.g. `en`, `es`, `fr`, etc. (lowercase)
  * - `country`: Language's country code, e.g. `US`, `ES`, `FR`, etc. (uppercase)
  * - `direction`: Language writing direction, possible values are "ltr" or "rtl".
  * - `icon`: Flag icon (it may be empty) e.g. `es.gif`, `es.gif`,
  *    icons files are located in Locale plugin's `/webroot/img/flags/` directory,
  *    to render an icon using HtmlHelper you should do as follow:
  *
  * ```php
  * <?= $this->Html->image('Locale.flags/' . language('icon')); ?>
  * ```
  *
  * @param string|null $key The key to read, or null to read the whole info
  * @return mixed
  */
 function language($key = null)
 {
     $code = I18n::locale();
     if ($key !== null) {
         return Configure::read("QuickApps.languages.{$code}.{$key}");
     }
     return Configure::read('QuickApps.languages.{$code}');
 }
 /**
  * Inspects the request for the Accept-Language header and sets the
  * Locale for the current runtime if it matches the list of valid locales
  * as passed in the configuration.
  *
  * @param \Cake\Event\Event $event The event instance.
  * @return void
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     $locale = Locale::acceptFromHttp($request->header('Accept-Language'));
     if (!$locale || !empty($this->_locales) && !in_array($locale, $this->_locales)) {
         return;
     }
     I18n::locale($locale);
 }
Example #10
0
 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * @return void
  */
 public function initialize()
 {
     I18n::locale('fr_FR');
     $this->loadComponent('Flash');
     $this->loadComponent('Auth', ['authenticate' => ['Form' => ['fields' => ['username' => 'email', 'password' => 'password']]], 'loginAction' => ['controller' => 'Users', 'action' => 'login']]);
     // Allow the display action so our pages controller
     // continues to work.
     $this->Auth->allow(['login']);
 }
 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * e.g. `$this->loadComponent('Security');`
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     $this->loadComponent('RequestHandler');
     $this->loadComponent('Flash');
     if ($this->request->session()->check('Config.locale')) {
         I18n::locale($this->request->session()->read('Config.locale'));
         // cambio del idioma
     }
 }
Example #12
0
 /**
  * Check for browser language and set website language to it
  *
  * @return void
  */
 protected function checkLanguage()
 {
     if (!empty($_GET['lang'])) {
         $this->request->session()->write('lang', $_GET['lang']);
         I18n::locale($_GET['lang']);
     } else {
         $lang = $this->request->session()->read('lang');
         I18n::locale($lang);
     }
 }
Example #13
0
 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     $this->_setLanguage();
     $language = $this->request->session()->read('Config.language');
     I18n::locale($language);
     if (!$this->request->session()->check('User') && $this->action == 'admin_login') {
         $this->redirect('/admin/admin_login');
     }
 }
Example #14
0
 /**
  * Test tokenExpired another locale
  *
  * @return void
  */
 public function testTokenExpiredLocale()
 {
     I18n::locale('es_AR');
     $this->User->token_expires = '+1 day';
     $isExpired = $this->User->tokenExpired();
     $this->assertFalse($isExpired);
     $this->User->token_expires = '-1 day';
     $isExpired = $this->User->tokenExpired();
     $this->assertTrue($isExpired);
 }
 /**
  * Index method
  *
  * @return void
  */
 public function change($locale = null)
 {
     if ($locale == null) {
         $locale = 'en_US';
     }
     I18n::locale($locale);
     $session = $this->request->session();
     $session->write('locale', $locale);
     $this->redirect($this->referer());
 }
Example #16
0
 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     $this->loadComponent('Flash');
     $this->_setLanguage();
     $session = $this->request->session();
     $locale = strtolower($session->read('Config.language')) . '_' . strtoupper($session->read('Config.language'));
     I18n::locale($locale);
     $this->set('language', $session->read('Config.language'));
 }
 /**
  * @param ServerRequestInterface $request  The request.
  * @param ResponseInterface $response The response.
  * @param callable $next The next middleware to call.
  * @return \Psr\Http\Message\ResponseInterface A response.
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     $locale = Locale::acceptFromHttp($request->getHeaderLine('Accept-Language'));
     if (!$locale) {
         return $next($request, $response);
     }
     if (in_array($locale, $this->locales) || $this->locales === ['*']) {
         I18n::locale($locale);
     }
     return $next($request, $response);
 }
Example #18
0
 public function beforeRender(Event $event)
 {
     if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml'])) {
         $this->set('_serialize', true);
     }
     $session = $this->request->session();
     if (!$session->check('Config.language')) {
         $session->write('Config.language', 'fr');
     } else {
         I18n::locale($session->read('Config.language'));
     }
 }
Example #19
0
 public function setLocale($locale = null)
 {
     switch ($locale) {
         case 'en':
             I18n::locale('en');
             break;
         default:
             I18n::locale('pt');
             break;
     }
     $this->request->session()->write('locale.locale', $locale);
 }
Example #20
0
 /**
  * Internal function to generate datepicker and timepicker.
  *
  * Bootstrap Datepicker and Moment.js should be installed via Composer.
  * @param string $input Target field
  * @param array $options Options for the datepicker
  * @return string jQuery code
  * @see http://eonasdan.github.io/bootstrap-datetimepicker Bootstrap 3 Datepicker v4 documentation
  * @uses Assets\View\Helper\AssetHelper::css()
  * @uses Assets\View\Helper\AssetHelper::script()
  */
 protected function _datetimepicker($input, array $options = [])
 {
     $this->Asset->script(['/vendor/moment/moment-with-locales.min', '/vendor/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min'], ['block' => 'script_bottom']);
     $this->Asset->css('/vendor/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min', ['block' => 'css_bottom']);
     $options = $this->optionsDefaults(['showTodayButton' => true, 'showClear' => true], $options);
     if (!isset($options['icons'])) {
         $options['icons'] = ['time' => 'fa fa-clock-o', 'date' => 'fa fa-calendar', 'up' => 'fa fa-arrow-up', 'down' => 'fa fa-arrow-down', 'previous' => 'fa fa-arrow-left', 'next' => 'fa fa-arrow-right', 'today' => 'fa fa-dot-circle-o', 'clear' => 'fa fa-trash'];
     }
     //Sets the current locale
     $locale = substr(\Cake\I18n\I18n::locale(), 0, 2);
     $options = $this->optionsDefaults(['locale' => empty($locale) ? 'en-gb' : $locale], $options);
     return sprintf('$("%s").datetimepicker(%s);', $input, json_encode($options, JSON_PRETTY_PRINT));
 }
Example #21
0
 /**
  * Test parsing a file with message context on some msgid values.
  *
  * This behavior is not ideal, but more thorough solutions
  * would break compatibility. Perhaps this is something we can
  * reconsider in 4.x
  *
  * @return void
  */
 public function testParseContextOnSomeMessages()
 {
     $parser = new PoFileParser();
     $file = APP . 'Locale' . DS . 'en' . DS . 'context.po';
     $messages = $parser->parse($file);
     I18n::translator('default', 'en_US', function () use($messages) {
         $package = new Package('default');
         $package->setMessages($messages);
         return $package;
     });
     $this->assertTextEquals('En cours', $messages['Pending']);
     $this->assertTextEquals('En resolved', $messages['Resolved']);
 }
Example #22
0
 /**
  * Constructor
  *
  * @param View $view View
  * @param array $config Config
  *
  * @return void
  */
 public function __construct(View $view, $config = [])
 {
     parent::__construct($view, $config);
     // Merge Options given by user in config/recaptcha
     $configRecaptcha = Configure::read('Recaptcha');
     $this->config($configRecaptcha);
     $lang = $this->config('lang');
     if (empty($lang)) {
         $this->config('lang', I18n::locale());
     }
     // Validate the Configure Data
     // unset secret param
     $this->config('secret', '');
 }
 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * e.g. `$this->loadComponent('Security');`
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     $this->loadComponent('RequestHandler');
     $this->loadComponent('Flash');
     $this->loadComponent('Auth', ['loginRedirect' => ['controller' => 'Receipts', 'action' => 'index'], 'logoutRedirect' => ['controller' => 'Pages', 'action' => 'home']]);
     if (!empty($this->request->session()->read('locale'))) {
         $locale = $this->request->session()->read('locale');
     } else {
         $locale = 'en_US';
         $session = $this->request->session();
         $session->write('locale', $locale);
     }
     I18n::locale($locale);
 }
Example #24
0
    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $timestamp = null;
        $locale = locale_get_primary_language(I18n::locale());
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTime && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            $timestamp = $val->format('U');
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
                    data-timestamp="{$timestamp}"
                    {$required}
                />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
html;
        return $widget;
    }
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     TableRegistry::clear();
     Cache::disable();
     Router::reload();
     //Router::fullBaseUrl('http://test.local');
     Router::scope('/', function ($routes) {
         $routes->fallbacks('DashedRoute');
     });
     $this->Articles = TableRegistry::get('Articles', ['className' => 'Seo\\Test\\TestCase\\Model\\Behavior\\ArticlesTable']);
     $this->Articles->addBehavior('Seo.Seo', $this->defaultConfig);
     $this->SeoBehavior = new SeoBehavior($this->Articles, $this->defaultConfig);
     $this->setReflectionClassInstance($this->SeoBehavior);
     //$this->defaultReflectionTarget = $this->SeoBehavior; // (optional)
     $this->defaultEntity = $this->Articles->find()->first();
     $this->locale = I18n::locale();
 }
Example #26
0
 /**
  * Before filter callback
  *
  * @param \Cake\Event\Event $event The beforeFilter event.
  *
  * @return void
  */
 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     $this->Auth->allow();
     // SFW
     $this->set('seeNSFW', $this->request->session()->read('seeNSFW'));
     // Languages
     $lang = $this->request->session()->read('language');
     $this->set('availableLanguages', $this->request->session()->read('languages'));
     $this->set('siteLanguage', $lang);
     I18n::locale($this->_getFolderNameFromLangCode($lang));
     // User menu
     $authUser = null;
     if (!is_null($this->Auth->user('id'))) {
         $authUser = $this->Auth->user();
     }
     $this->set('authUser', $authUser);
 }
Example #27
0
 /**
  * Constructor
  *
  * @param View $view View
  * @param array $config Config
  *
  * @return void
  */
 public function __construct(View $view, $config = [])
 {
     parent::__construct($view, $config);
     // Merge Options given by user in config/recaptcha
     $this->config(Configure::read('Recaptcha'));
     $lang = $this->config('lang');
     if (empty($lang)) {
         $this->config('lang', I18n::locale());
     }
     // Validate the Configure Data
     $validator = new RecaptchaValidator();
     $errors = $validator->errors($this->config());
     if (!empty($errors)) {
         throw new \Exception(__d('recaptcha', 'One of your recaptcha config value is incorrect'));
         // throw an exception with config error that is raised
     }
     // Make sure the secret param is
     $this->config('secret', '');
 }
Example #28
0
 public function initialize()
 {
     parent::initialize();
     $this->loadComponent('Flash');
     $this->loadComponent('Session');
     $language = $this->request->session()->read('language');
     if ($language) {
         switch ($language) {
             case "fr":
                 I18n::locale('fr_CA');
                 break;
             case "en":
                 I18n::locale('en_CA');
                 break;
             default:
                 I18n::locale('en_CA');
                 break;
         }
     } else {
         $this->request->session()->write('language', 'en');
     }
     if (isset($this->request['prefix'])) {
         if ($this->request['prefix'] == 'admin') {
             $this->loadComponent('Auth', ['loginAction' => ['controller' => 'Main', 'action' => 'login', 'prefix' => 'admin'], 'logoutAction' => ['controller' => 'Main', 'action' => 'logout', 'prefix' => 'admin'], 'logoutRedirect' => ['controller' => 'Main', 'action' => 'index', 'prefix' => false], 'loginRedirect' => ['controller' => 'Main', 'action' => 'index', 'prefix' => 'admin'], 'authenticate' => ['Form' => ['userModel' => 'Admins', 'fields' => ['username' => 'username', 'password' => 'password'], 'passwordHasher' => ['className' => 'Fallback', 'hashers' => ['Default', 'Legacy']]]], 'authorize' => 'Controller', 'unauthorizedRedirect' => $this->request->referer()]);
             $this->layout = 'admin';
             $this->_setAdminUIVariables();
         } else {
             if ($this->request['prefix'] == 'agent') {
                 $this->loadComponent('Auth', ['autoRedirect' => false, 'loginAction' => ['controller' => 'Main', 'action' => 'login', 'prefix' => 'agent'], 'logoutAction' => ['controller' => 'Main', 'action' => 'logout', 'prefix' => 'agent'], 'logoutRedirect' => ['controller' => 'Main', 'action' => 'index', 'prefix' => false], 'loginRedirect' => ['controller' => 'brochures', 'action' => 'index', 'prefix' => 'agent'], 'authenticate' => ['Form' => ['userModel' => 'Agents', 'fields' => ['username' => 'username', 'password' => 'password'], 'scope' => array('Agents.status' => 1), 'passwordHasher' => ['className' => 'Fallback', 'hashers' => ['Default', 'Legacy']]]], 'authorize' => 'Controller', 'unauthorizedRedirect' => $this->request->referer()]);
                 $this->layout = 'agent';
                 $this->_initShoppingCart();
             } else {
                 if ($this->request['prefix'] == 'supplier') {
                     $this->loadComponent('Auth', ['loginAction' => ['controller' => 'Main', 'action' => 'login', 'prefix' => 'supplier'], 'logoutAction' => ['controller' => 'Main', 'action' => 'logout', 'prefix' => 'supplier'], 'logoutRedirect' => ['controller' => 'Main', 'action' => 'index', 'prefix' => false], 'loginRedirect' => ['controller' => 'Main', 'action' => 'index', 'prefix' => 'supplier'], 'authenticate' => ['Form' => ['userModel' => 'Suppliers', 'fields' => ['username' => 'username', 'password' => 'password'], 'passwordHasher' => ['className' => 'Fallback', 'hashers' => ['Default', 'Legacy']]]], 'authorize' => 'Controller', 'unauthorizedRedirect' => $this->request->referer()]);
                     $this->layout = 'supplier';
                     $this->_initShoppingCart();
                     $suppliername = $this->Auth->user('company');
                     $this->set('suppliername', $suppliername);
                 }
             }
         }
     }
 }
 /**
  * Switch language as post link.
  *
  * @param string|null $language
  * @return \Cake\Network\Response
  */
 public function language($language = null)
 {
     $this->request->allowMethod(['post']);
     $allowedLanguages = (array) Configure::read('Config.allowedLanguages');
     if (!$language) {
         $language = Configure::read('Config.defaultLanguage');
     }
     if (!$language) {
         $keys = array_keys($allowedLanguages);
         $language = $allowedLanguages[array_shift($keys)];
     }
     if (!array_key_exists($language, $allowedLanguages)) {
         throw new \RuntimeException('Invalid Language');
     }
     $language = $allowedLanguages[$language];
     $this->request->session()->write('Config.language', $language['locale']);
     I18n::locale($language['locale']);
     $this->Flash->success(__d('tools', 'Language switched to {0}', $language['name']));
     return $this->redirect($this->referer('/', true));
 }
 /**
  * Edit a category.
  *
  * @return \Cake\Network\Response|void
  */
 public function edit()
 {
     $this->loadModel('BlogCategories');
     $this->BlogCategories->locale(I18n::defaultLocale());
     $category = $this->BlogCategories->find('slug', ['slug' => $this->request->slug, 'slugField' => 'BlogCategories.slug'])->find('translations')->first();
     //Check if the category is found.
     if (empty($category)) {
         $this->Flash->error(__d('admin', 'This category doesn\'t exist or has been deleted.'));
         return $this->redirect(['action' => 'index']);
     }
     if ($this->request->is('put')) {
         $this->BlogCategories->patchEntity($category, $this->request->data());
         $category->setTranslations($this->request->data);
         if ($this->BlogCategories->save($category)) {
             $this->Flash->success(__d('admin', 'This category has been updated successfully !'));
             return $this->redirect(['action' => 'index']);
         }
     }
     $this->set(compact('category'));
 }