本文整理汇总了PHP中app\models\Language类的典型用法代码示例。如果您正苦于以下问题:PHP Language类的具体用法?PHP Language怎么用?PHP Language使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Language类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create($firstName = '', $lastName = '', $email = '', $password = '')
{
$account = new Account();
$account->ip = Request::getClientIp();
$account->account_key = str_random(RANDOM_KEY_LENGTH);
// Track referal code
if ($referralCode = Session::get(SESSION_REFERRAL_CODE)) {
if ($user = User::whereReferralCode($referralCode)->first()) {
$account->referral_user_id = $user->id;
}
}
if ($locale = Session::get(SESSION_LOCALE)) {
if ($language = Language::whereLocale($locale)->first()) {
$account->language_id = $language->id;
}
}
$account->save();
$user = new User();
if (!$firstName && !$lastName && !$email && !$password) {
$user->password = str_random(RANDOM_KEY_LENGTH);
$user->username = str_random(RANDOM_KEY_LENGTH);
} else {
$user->first_name = $firstName;
$user->last_name = $lastName;
$user->email = $user->username = $email;
$user->password = bcrypt($password);
}
$user->confirmed = !Utils::isNinja();
$user->registered = !Utils::isNinja() && $user->email;
if (!$user->confirmed) {
$user->confirmation_code = str_random(RANDOM_KEY_LENGTH);
}
$account->users()->save($user);
return $account;
}
示例2: edit
public function edit($id)
{
$param['pageNo'] = 2;
$result = LanguageModel::find($id);
$param['language'] = $result;
return View::make('languages.edit')->with($param);
}
示例3: setLanguage
private function setLanguage()
{
$request = Yii::$app->request;
$cookie = $request->cookies->get('language');
if ($cookie) {
$lang = Language::findOne(['lang' => $cookie->value]);
if ($lang) {
Yii::$app->language = $lang->lang;
return;
}
}
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$accepts = $request->parseAcceptHeader($_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($accepts as $lang => $options) {
//FIXME: DBと整合をとってちゃんとやる
switch (strtolower($lang)) {
case 'ja':
case 'ja-jp':
Yii::$app->language = 'ja-JP';
return;
case 'en':
case 'en-US':
Yii::$app->language = 'en-US';
return;
}
}
}
Yii::$app->language = 'en-US';
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
try {
//DELETE TABLES
DB::table('osu_genres')->delete();
DB::table('osu_languages')->delete();
//COUNTS
if (!DB::table('osu_counts')->where('name', 'pp_rank_column')->get()) {
DB::table('osu_counts')->insert([['name' => 'pp_rank_column', 'count' => 90], ['name' => 'usercount', 'count' => 500000]]);
}
//END COUNTS
//GENRES
DB::table('osu_genres')->insert([['genre_id' => 99, 'name' => 'Any'], ['genre_id' => 1, 'name' => 'Unspecified'], ['genre_id' => 2, 'name' => 'Video Game'], ['genre_id' => 3, 'name' => 'Anime'], ['genre_id' => 4, 'name' => 'Rock'], ['genre_id' => 5, 'name' => 'Pop'], ['genre_id' => 6, 'name' => 'Other'], ['genre_id' => 7, 'name' => 'Novelty'], ['genre_id' => 9, 'name' => 'Hip Hop'], ['genre_id' => 10, 'name' => 'Electronic']]);
$any_genre = \App\Models\Genre::find(99);
$any_genre->genre_id = 0;
$any_genre->save();
// END GENRES
//LANGUAGES
DB::table('osu_languages')->insert([['language_id' => 99, 'name' => 'Any', 'display_order' => 0], ['language_id' => 1, 'name' => 'Other', 'display_order' => 11], ['language_id' => 2, 'name' => 'English', 'display_order' => 1], ['language_id' => 3, 'name' => 'Japanese', 'display_order' => 6], ['language_id' => 4, 'name' => 'Chinese', 'display_order' => 2], ['language_id' => 5, 'name' => 'Instrumental', 'display_order' => 10], ['language_id' => 6, 'name' => 'Korean', 'display_order' => 7], ['language_id' => 7, 'name' => 'French', 'display_order' => 3], ['language_id' => 8, 'name' => 'German', 'display_order' => 4], ['language_id' => 9, 'name' => 'Swedish', 'display_order' => 9], ['language_id' => 10, 'name' => 'Spanish', 'display_order' => 8], ['language_id' => 11, 'name' => 'Italian', 'display_order' => 5]]);
$any_language = \App\Models\Language::find(99);
$any_language->language_id = 0;
$any_language->save();
//END LANGUAGES
} catch (\Illuminate\Database\QueryException $e) {
echo $e->getMessage() . "\r\n";
} catch (Exception $ex) {
echo $ex->getMessage() . "\r\n";
}
}
示例5: edit
public function edit($id)
{
$param['pageNo'] = 1;
$result = DomainModel::find($id);
$param['domain'] = $result;
$param['language'] = LanguageModel::all();
$param['template'] = TemplateModel::all();
return View::make('domains.edit')->with($param);
}
示例6: getAutoCompleteWordsAjax
public function getAutoCompleteWordsAjax(Request $request)
{
if (!$request->ajax()) {
return response()->json(['response' => 'reject', 'msg' => 'request Not Allowed', 'searchWord' => $request->searchWord, 'language' => $request->languageName, 'Ajax' => $request->ajax(), 'Request' => $request->method()]);
}
$searchWord = $request->searchWord;
$languageId = Language::where('id', '=', $request->languageId)->value('id');
$Words = Word::where('language_id', '=', $languageId)->where('word', 'LIKE', $searchWord . '%')->orderBy('word', 'asc')->limit(10)->get();
return $Words;
}
示例7: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$now = date('Y-m-d H:i:s', strtotime('now'));
$languages = [['name' => 'english', 'description' => 'the Language English', 'created_at' => $now, 'updated_at' => $now], ['name' => 'danish', 'description' => 'the Language Danish, spoken in Denmark', 'created_at' => $now, 'updated_at' => $now], ['name' => 'pashto', 'description' => 'the Language Pashto, spoken in Afghanistan', 'created_at' => $now, 'updated_at' => $now]];
foreach ($languages as $language) {
if (\App\Models\Language::where('name', '=', $language['name'])->exists()) {
echo $language['name'] . " Already exists\n";
} else {
\App\Models\Language::create($language);
}
}
//DB::table('words')->truncate();
//Schema::drop('words');
$passed = 0;
$exists = 0;
//word table - seed from a file
// $pashto_json = File::get(storage_path() . "/app/json_data/pashto.json");
// $pashto_word = json_decode($pashto_json);
//
// foreach ($pashto_word as $wordObj)
// {
// if(\App\Models\Word::where('word', '=', $wordObj->s2p[0])->exists())
// {
// echo $wordObj->s2p[0] . " Already exists\n";
// $exists++;
// }
// else
// {
// \App\Models\Word::create([
// 'language_id' => 3,
// 'user_id' => 3,
// 'word' => $wordObj->s2p[0],
// 'pronounce_audio_path' => '',
// 'pronounce_text' => 'pronounce_text missing',
// 'definition' => 'Word definition missing',
// 'created_at' => $now,
// 'updated_at' => $now,
// ]);
//
// $passed++;
// }
// }
foreach (File(storage_path() . "/app/danskOrde_49389.txt", FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES) as $word) {
if (App\Models\Word::where(['language_id' => 2, 'word' => $word])->exists()) {
echo $word . ": Already exists in Danish\n";
$exists++;
} else {
App\Models\Word::create(['language_id' => 2, 'user_id' => 3, 'word' => $word, 'pronounce_audio_path' => '', 'pronounce_text' => 'pronounce_text missing', 'definition' => 'Word definition missing', 'created_at' => $now, 'updated_at' => $now]);
$passed++;
}
}
echo "\n Words Already Exists: " . $exists;
echo "\n Words added: " . $passed . "\n";
}
示例8: detectLanguageByCookie
private function detectLanguageByCookie()
{
$cookie = Yii::$app->request->cookies->get('language');
if (!$cookie) {
return false;
}
if (!($lang = Language::findOne(['lang' => $cookie->value]))) {
return false;
}
return $lang->lang;
}
示例9: actionSelect
public function actionSelect($id, $current_url = '')
{
$language = Language::findOne($id);
Yii::$app->response->cookies->add(new Cookie(['name' => 'language', 'value' => $language->code, 'expire' => (new \Datetime())->modify('+1 year')->getTimestamp()]));
if ($current_url) {
$current_url = urldecode($current_url);
} else {
$current_url = ['site/index'];
}
return $this->redirect($current_url);
}
示例10: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Language::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['l_id' => $this->l_id]);
$query->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
示例11: translateToAll
public function translateToAll($category, $message, $params = [])
{
if (self::$langs === null) {
self::$langs = Language::find()->all();
}
$i18n = Yii::$app->i18n;
$ret = [];
foreach (self::$langs as $lang) {
$ret[strtr($lang->lang, '-', '_')] = $i18n->translate($category, $message, $params, $lang->lang);
}
return $ret;
}
示例12: init
public function init()
{
parent::init();
if ($this->currentLanguage === null) {
$this->currentLanguage = Language::getCurrent();
}
if ($this->allowedLanguages === null) {
$this->allowedLanguages = Language::find()->where('`id` != :id', [':id' => $this->currentLanguage->id])->all();
}
$this->cssClass .= ' dropdown dropdown-language';
$this->options['class'] = trim($this->cssClass);
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Language::find();
$pageSize = Yii::$app->session->get('pageSize', Yii::$app->params['defaultPageSize']);
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize]]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['l_id' => $this->l_id]);
$query->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'message', $this->message]);
return $dataProvider;
}
示例14: setLanguage
private function setLanguage()
{
$request = Yii::$app->request;
$cookie = $request->cookies->get('language');
if ($cookie) {
$lang = Language::findOne(['lang' => $cookie->value]);
if ($lang) {
Yii::$app->language = $lang->lang;
return;
}
}
}
示例15: getLangByUrl
static function getLangByUrl($url = null)
{
if ($url === null) {
return null;
} else {
$language = Language::find()->where('url = :url', [':url' => $url])->one();
if ($language === null) {
return null;
} else {
return $language;
}
}
}