当前位置: 首页>>代码示例>>PHP>>正文


PHP Str::slug方法代码示例

本文整理汇总了PHP中Str::slug方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::slug方法的具体用法?PHP Str::slug怎么用?PHP Str::slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Str的用法示例。


在下文中一共展示了Str::slug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save()
 {
     $id = Input::get('id');
     $ct = $this->category->find($id);
     $token = \Input::get('_token');
     if (\Session::token() === $token) {
         $data = array('ten_vi' => Input::get('ten_vi'), 'hienthi' => Input::has('hienthi'), 'parent' => Input::get('category'), 'slug_vi' => \Str::slug(Input::get('ten_vi'), '-'), 'title_seo_vi' => Input::get('title_seo_vi'), 'desc_seo_vi' => Input::get('desc_seo_vi'), 'keyword_seo_vi' => Input::get('keyword_seo_vi'));
         // var_dump($data);die();
         $ct->hienthi = $data['hienthi'];
         $ct->ten_vi = $data['ten_vi'];
         $ct->slug_vi = $data['slug_vi'];
         $ct->parent = $data['parent'];
         $ct->title_seo_vi = $data['title_seo_vi'];
         $ct->desc_seo_vi = $data['desc_seo_vi'];
         $ct->keyword_seo_vi = $data['keyword_seo_vi'];
         /* avoiding resubmission of same content */
         if (count($ct->getDirty()) > 0) {
             \DB::beginTransaction();
             try {
                 $ct->save();
             } catch (\Exception $e) {
                 \DB::rollBack();
                 return \Redirect::back()->withInput()->with('success', 'ERROR : Update fail');
             }
             \DB::commit();
             return \Redirect::back()->withInput()->with('success', 'Cập nhật thành công');
         } else {
             return \Redirect::back()->withInput()->with('success', 'Không thay đổi gì');
         }
     } else {
         return \Redirect::back()->withInput()->with('success', 'Cập nhật thất bại, Token hết hiệu lực');
     }
 }
开发者ID:anhtuanssp,项目名称:createyourown_vn_inqua,代码行数:33,代码来源:AdminChuyenmucController.php

示例2: make

 public static function make($string, $table = [], $exclude_id = 0, $column = 'slug')
 {
     # $table can be array
     if (is_array($table)) {
         $uniques = array_values($table);
     } else {
         $uniques = DB::table($table)->where('id', '<>', $exclude_id)->lists($column);
         if (empty($uniques)) {
             $uniques = [];
         }
     }
     # Convert string into array of url-friendly words
     $words = explode('-', Str::slug($string, '-'));
     # Words should be unique
     $words = array_unique($words);
     # Remove stop words
     $words = array_diff($words, self::$stop_words);
     # Reset indexes
     $words = array_values($words);
     # Limit length of slug down to fewer than 50 characters
     while (self::checkLength($words) === false) {
         array_pop($words);
     }
     # Check uniqueness
     while (self::checkUniqueness($words, $uniques) === false) {
         self::increment($words);
     }
     return self::makeFromWords($words);
 }
开发者ID:joshreisner,项目名称:avalon,代码行数:29,代码来源:Slug.php

示例3: postEdit

 public function postEdit($id)
 {
     if (!$this->checkRoute()) {
         return Redirect::route('index');
     }
     $title = 'Edit A Modpack Creator - ' . $this->site_name;
     $creator = Creator::find($id);
     $input = Input::only('name', 'deck', 'website', 'donate_link', 'bio', 'slug');
     $messages = ['unique' => 'The modpack creator already exists in the database.', 'url' => 'The :attribute field is not a valid URL.'];
     $validator = Validator::make($input, ['name' => 'required|unique:creators,name,' . $creator->id, 'website' => 'url', 'donate_link' => 'url'], $messages);
     if ($validator->fails()) {
         return Redirect::action('CreatorController@getAdd')->withErrors($validator)->withInput();
     }
     $creator->name = $input['name'];
     $creator->deck = $input['deck'];
     $creator->website = $input['website'];
     $creator->donate_link = $input['donate_link'];
     $creator->bio = $input['bio'];
     if ($input['slug'] == '' || $input['slug'] == $creator->slug) {
         $slug = Str::slug($input['name']);
     } else {
         $slug = $input['slug'];
     }
     $creator->slug = $slug;
     $creator->last_ip = Request::getClientIp();
     $success = $creator->save();
     if ($success) {
         return View::make('creators.edit', ['title' => $title, 'creator' => $creator, 'success' => true]);
     }
     return Redirect::action('CreatorController@getEdit', [$id])->withErrors(['message' => 'Unable to edit modpack creator.'])->withInput();
 }
开发者ID:helkarakse,项目名称:modpackindex,代码行数:31,代码来源:CreatorController.php

示例4: updateCategory

 public function updateCategory()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     if (Input::has('pk')) {
         return self::updateQuickEdit();
     }
     $arrReturn = ['status' => 'error'];
     $category = new Category();
     $category->name = Input::get('name');
     $category->short_name = Str::slug($category->name);
     $category->description = Input::get('description');
     $category->parent_id = (int) Input::get('parent_id');
     $category->order_no = (int) Input::get('order_no');
     $category->active = Input::has('active') ? 1 : 0;
     $pass = $category->valid();
     if ($pass) {
         $category->save();
         $arrReturn = ['status' => 'ok'];
         $arrReturn['message'] = $category->name . ' has been saved';
         $arrReturn['data'] = $category;
     } else {
         $arrReturn['message'] = '';
         $arrErr = $pass->messages()->all();
         foreach ($arrErr as $value) {
             $arrReturn['message'] .= "{$value}\n";
         }
     }
     return $arrReturn;
 }
开发者ID:nguyendaivu,项目名称:imagestock,代码行数:31,代码来源:CategoriesController.php

示例5: postEdit

 public function postEdit($slug)
 {
     $album = $this->repo->album($slug);
     if (!\Request::get('name')) {
         \Flash::error('Musisz podać nazwę.');
         return \Redirect::back()->withInput();
     }
     $name = \Request::get('name');
     $slug = \Str::slug($name);
     $description = \Request::get('description');
     $exists = $this->repo->album($slug);
     if ($exists && $exists->id != $album->id) {
         \Flash::error('Album z tą nazwą już istnieje.');
         return \Redirect::back()->withInput();
     }
     if (\Input::hasFile('image')) {
         $image_name = \Str::random(32) . \Str::random(32) . '.png';
         $image = \Image::make(\Input::file('image')->getRealPath());
         $image->save(public_path('assets/gallery/album_' . $image_name));
         $callback = function ($constraint) {
             $constraint->upsize();
         };
         $image->widen(480, $callback)->heighten(270, $callback)->resize(480, 270);
         $image->save(public_path('assets/gallery/album_thumb_' . $image_name));
         $album->image = $image_name;
     }
     $album->name = $name;
     $album->slug = $slug;
     $album->description = $description;
     $album->save();
     \Flash::success('Pomyślnie edytowano album.');
     return \Redirect::to('admin/gallery/' . $slug . '/edit');
 }
开发者ID:kkstudio,项目名称:gallery,代码行数:33,代码来源:GalleryController.php

示例6: action_edit

 public function action_edit($id)
 {
     $post = \Blog\Models\Post::find($id);
     if ($post === null) {
         return Event::first('404');
     }
     if (Str::lower(Request::method()) == "post") {
         $validator = Validator::make(Input::all(), self::$rules);
         if ($validator->passes()) {
             $post->title = Input::get('title');
             if (Input::get('slug')) {
                 $post->slug = Str::slug(Input::get('slug'));
             } else {
                 $post->slug = Str::slug(Input::get('title'));
             }
             $post->intro = Input::get('intro');
             $post->content = Input::get('content');
             $post->author_id = Input::get('author_id');
             $post->category_id = Input::get('category_id');
             $post->publicated_at = Input::get('publicated_at_date') . ' ' . Input::get('publicated_at_time');
             $post->save();
             return Redirect::to_action('blog::admin.post@list');
         } else {
             return Redirect::back()->with_errors($validator)->with_input();
         }
     } else {
         $categories = array();
         $originalCategories = \Blog\Models\Category::all();
         foreach ($originalCategories as $cat) {
             $categories[$cat->id] = $cat->name;
         }
         return View::make('blog::admin.post.new')->with_post($post)->with('editMode', true)->with('categories', $categories);
     }
 }
开发者ID:marmaray,项目名称:OLD-laravel-France-website,代码行数:34,代码来源:post.php

示例7: apply

 public function apply($id)
 {
     $job = DB::select("EXEC spJobByID_Select @JobID = {$id}")[0];
     $data = [];
     $data['job'] = $job;
     $data['form'] = Input::all();
     $email = Input::get('email');
     $name = Input::get('name');
     if (Input::hasFile('cv')) {
         $newfilename = Str::slug($name) . '_cv_' . uniqid() . '.' . Input::file('cv')->getClientOriginalExtension();
         Input::file('cv')->move(public_path() . '/uploads/cvs/', $newfilename);
         Mail::send('emails.jobs.apply', $data, function ($message) use($email, $name, $newfilename, $job) {
             $message->to($email, $name)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo);
             $message->bcc($job->OperatorEmail, $job->OperatorName . ' ' . $job->OperatorSurname)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo);
             $message->attach(public_path() . '/uploads/cvs/' . $newfilename);
         });
     } else {
         // Send email to KDC
         Mail::send('emails.jobs.apply', $data, function ($message) use($email, $name, $job) {
             $message->to($email, $name)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo);
             $message->bcc($job->OperatorEmail, $job->OperatorName . ' ' . $job->OperatorSurname)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo);
             $message->bcc('it_support@kdc-group.co.uk', 'KDC')->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo);
         });
     }
     return Redirect::back()->withInfo('Your application has been sent');
 }
开发者ID:TheCompleteCode,项目名称:laravel-kdc,代码行数:26,代码来源:JobController.php

示例8: postsettings

 /**
  * Save charity settings
  *
  * @return Response
  */
 public function postsettings()
 {
     $input = Input::all();
     $profile = User::find(Auth::user()->id);
     if (!$profile->charity) {
         $charity = new Charity();
     } else {
         $charity = Charity::find($profile->charity_id);
     }
     $charity->name = $input['name'];
     $charity->goal = $input['goal'];
     $charity->description = $input['description'];
     $charity->save();
     $profile->charity_id = $charity->id;
     $profile->profile_url = Str::slug($input['name']);
     $profile->phone = $input['phone'];
     $profile->country = $input['country'];
     $profile->city = $input['city'];
     $profile->picture = $input['picture_id'];
     $profile->zip = $input['zip'];
     $profile->paypal = $input['paypal'];
     //Disabling validation rules
     $profile::$rules['email'] = '';
     $profile::$rules['agree'] = '';
     $profile->autoHashPasswordAttributes = false;
     if ($profile->save(['charity_id' => 'required|exists:charity,id', 'profile_url' => 'unique:users,profile_url,' . $profile->id])) {
         return Redirect::to('/charity/' . $profile->profile_url);
     } else {
         return Redirect::to('charity/settings')->with('errors', $profile->errors()->all());
     }
 }
开发者ID:centaurustech,项目名称:musicequity,代码行数:36,代码来源:CharityController.php

示例9: toApplication

 /**
  *	@param url $url protocol to redirect to
  *	@return ApiResponse Response to client
  */
 public static function toApplication($url_suffix, $protocol = null)
 {
     $response = self::make();
     $protocol = empty($protocol) ? Str::slug(Config::get('app.name')) : $protocol;
     $response->header('Location', $protocol . '://' . $url_suffix);
     return $response;
 }
开发者ID:jiqiang90,项目名称:laravel-restful-api-starter,代码行数:11,代码来源:ApiResponse.php

示例10: update

 public function update()
 {
     $rules = array('name' => 'required', 'desc' => 'required', 'totalposts' => 'required|numeric');
     $validator = Validator::make(Input::all(), $rules);
     $badgeid = Input::get('id');
     if ($validator->fails()) {
         return Redirect::to('admin/editbadge/' . $badgeid)->withErrors($validator)->withInput();
     } else {
         $name = Input::get('name');
         if (Input::get('badge')) {
             $image = explode('/', Input::get('badge'));
             $image = urldecode(end($image));
             $extension = explode(".", $image);
             $extension = end($extension);
             $img = Image::make('files/' . $image);
             $img->resize(160, null, function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             })->save('files/' . $image);
             $newname = date('YmdHis') . '_' . Str::slug($name, '_') . '.' . $extension;
             File::move('files/' . $image, 'badges/' . $newname);
         }
         $badge = Badge::find($badgeid);
         $badge->name = Input::get('name');
         $badge->description = Input::get('desc');
         if (Input::get('badge')) {
             $badge->image = $newname;
         }
         $badge->total_posts = Input::get('totalposts');
         $badge->save();
         Session::flash('success', 'Badge updated');
         return Redirect::to('admin/badges');
     }
 }
开发者ID:ChavezRuston,项目名称:fansemo,代码行数:34,代码来源:BadgeController.php

示例11: boot

 public static function boot()
 {
     parent::boot();
     // Overriding the slug method to prefix with a forward slash
     self::$sluggable['method'] = function ($string, $sep) {
         return '/' . \Str::slug($string, $sep);
     };
     static::creating(function ($page) {
         // If the record is being created and there is a "main image" supplied, set it's width and height
         if (!empty($page->main_image)) {
             $page->updateMainImageSize();
         }
     });
     static::created(function ($page) {
         // If the record is being created and there is a "main image" supplied, set it's width and height
         if (!empty($page->main_image)) {
             $page->updateMainImageSize();
         }
     });
     static::updating(function ($page) {
         // If the record is about to be updated and there is a "main image" supplied, get the current main image
         // value so we can compare it to the new one
         $page->oldMainImage = self::where('id', '=', $page->id)->first()->pluck('main_image');
         return true;
     });
     static::updated(function ($page) {
         // If the main image has changed, and the save was successful, update the database with the new width and height
         if (isset($page->oldMainImage) && $page->oldMainImage != $page->main_image) {
             $page->updateMainImageSize();
         }
     });
 }
开发者ID:fbf,项目名称:laravel-pages,代码行数:32,代码来源:Page.php

示例12: post_create

 public function post_create()
 {
     $posts = Input::all();
     $title = $posts['thread_name'];
     $contentRaw = $posts['inputarea'];
     if ($title != '' && strlen($contentRaw) > 10) {
         $alias = Str::slug($title, '-');
         $exist = Thread::where('alias', '=', $alias)->first();
         if ($exist != null) {
             return Redirect::to($exist->id);
         }
         $threadData = array('title' => $posts['thread_name'], 'alias' => $alias, 'type' => 0, 'poster_ip' => Request::ip(), 'dateline' => date("Y-m-d H:i:s"), 'last_message_at' => date("Y-m-d H:i:s"));
         $thread = Thread::create($threadData);
         if ($thread != null) {
             $content = static::replace_at(BBCode2Html(strip_tags_attributes($contentRaw)), $thread->id);
             $postData = array('thread_id' => $thread->id, 'entry' => $content, 'userip' => Request::ip(), 'user_id' => Sentry::user()->id, 'datetime' => date("Y-m-d H:i:s"), 'count' => 1, 'type' => 0);
             $pst = Post::create($postData);
             if ($pst != null) {
                 return Redirect::to($thread->id);
             }
         }
     } else {
         return Redirect::to(URL::full());
     }
 }
开发者ID:TahsinGokalp,项目名称:L3-Sozluk,代码行数:25,代码来源:thread.php

示例13: update

 public function update($object_name)
 {
     //rename table if necessary
     $object = DB::table(DB_OBJECTS)->where('name', $object_name)->first();
     $new_name = Str::slug(Input::get('name'), '_');
     if ($object->name != $new_name) {
         Schema::rename($object->name, $new_name);
     }
     //enforce predence always ascending
     $order_by = Input::get('order_by');
     $direction = Input::get('direction');
     if ($order_by == 'precedence') {
         $direction = 'asc';
     }
     //not sure why it's necessary, doesn't like empty value all of a sudden
     $group_by_field = Input::has('group_by_field') ? Input::get('group_by_field') : null;
     //linked objects
     DB::table(DB_OBJECT_LINKS)->where('object_id', $object->id)->delete();
     if (Input::has('related_objects')) {
         foreach (Input::get('related_objects') as $linked_id) {
             DB::table(DB_OBJECT_LINKS)->insert(['object_id' => $object->id, 'linked_id' => $linked_id]);
         }
     }
     //update objects table
     DB::table(DB_OBJECTS)->where('id', $object->id)->update(['title' => Input::get('title'), 'name' => $new_name, 'model' => Input::get('model'), 'url' => Input::get('url'), 'order_by' => $order_by, 'direction' => $direction, 'singleton' => Input::has('singleton') ? 1 : 0, 'can_see' => Input::has('can_see') ? 1 : 0, 'can_create' => Input::has('can_create') ? 1 : 0, 'can_edit' => Input::has('can_edit') ? 1 : 0, 'list_grouping' => Input::get('list_grouping'), 'group_by_field' => $group_by_field, 'list_help' => trim(Input::get('list_help')), 'form_help' => trim(Input::get('form_help'))]);
     self::saveSchema();
     return Redirect::action('InstanceController@index', $new_name);
 }
开发者ID:joshreisner,项目名称:avalon,代码行数:28,代码来源:ObjectController.php

示例14: generateSlug

	protected function generateSlug($source)
	{
		$separator  = $this->sluggable['separator'];
		$method     = $this->sluggable['method'];
		$max_length = $this->sluggable['max_length'];

		if ( $method === null )
		{
			$slug = \Str::slug($source, $separator);
		}
		elseif ( $method instanceof Closure )
		{
			$slug = $method($source, $separator);
		}
		elseif ( is_callable($method) )
		{
			$slug = call_user_func($method, $source, $separator);
		}
		else
		{
			throw new \UnexpectedValueException("Sluggable method is not a callable, closure or null.");
		}

		if ($max_length)
		{
			$slug = substr($slug, 0, $max_length);
		}

		return $slug;
	}
开发者ID:hendryguna,项目名称:laravel-basic,代码行数:30,代码来源:SluggableTrait.php

示例15: contentItem

function contentItem($imagen, $nombrelook, $idlook, $imagenmarca, $textoTwitter, $categoria)
{
    $prod = '<img src="' . url() . '/img/lookbook/portada/' . Str::slug($imagen) . '.jpg" class="img-responsive" alt="' . $nombrelook . '" />
                                <div class="caption">
                                     
                                </div>
                                
                                    <a href="' . url() . '/lookbook/' . $idlook . '/' . Str::slug($categoria) . '/' . Str::slug($nombrelook) . '">
                                        
                                        <div class="boton-item-galeria">
                                            <div class="content-b-look"><img src="' . url() . '/img/lookbook/marcas/' . $imagenmarca . '" class="img-responsive"/></div>
                                        </div>
                                    </a>
                                
                                <div class="compartir-galeria">
                                    <img src="' . url() . '/images/sarah/compartelo.png"  alt="compartir" class="compartir-lookbook" />
                                    <div class="compartir-galeria-redes">
                                         <ul>
                                            <li><a href="https://www.facebook.com/sharer/sharer.php?u=' . url() . '/lookbook/' . $idlook . '/' . Str::slug($categoria) . '/' . Str::slug($nombrelook) . '" target="_blank"><img src="' . url() . '/img/facebook.png"  alt="facebook" /></a></li>
                                            <li><a href="https://twitter.com/home?status=' . $textoTwitter . '" target="_blank"><img src="' . url() . '/img/twitter.png"  alt="twitter" /></a></li>
                                        </ul>
                                    </div>
                                </div>';
    return $prod;
}
开发者ID:appsmambo,项目名称:tendencias-2015,代码行数:25,代码来源:lookbook.blade.php


注:本文中的Str::slug方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。