slug

parse URL with JavaScript or jQuery

不羁的心 提交于 2019-12-29 06:24:12
问题 Ok lets say I have a URL example.com/hello/world/20111020 (with or without the trailing slash). What I would like to do is strip from the url the domain example.com. and then break the hello world 20111020 into an array. But my other problem is. Sometimes the URL has no /hello/world/20111020 or just /hello/ so I need to first determine if there is anything after example.com if there not, then do nothing as obviously there's nothing to work with. However if there is something there for each /

Why SlugField() in Django?

送分小仙女□ 提交于 2019-12-29 03:17:26
问题 Django has models.SlugField() which helps us to create some cool looking urls. My question is why specifying it as a field suppose I have this model class Blog(models.Model): title = models.CharField() and if I want to add slug, I could just use class Blog(models.Model): title = models.CharField() def title_slug(self): return slugify(self.title) in urls I could just use (r'^blog/(?P<id>\d+)/(?P<slug>[-\w]+)/$', 'app.views.blog_view'), and in views def blog_view(request, id ,slug): get_object

Using slugs in laravel 5?

泪湿孤枕 提交于 2019-12-28 13:56:11
问题 I have made eloquent-sluggable work on my app. Slugs are saved just fine. Buuuut... How do I use it to create a pretty url? If possible, I would like to use them in my url instead of ID numbers. 回答1: Yes, you can use slug in your route and generated url , for example, if you declare a route something like this: Route::get('users/{username}', 'UserController@profile')->where('profile', '[a-z]+'); Then in your controller, you may declare the method like this: public function profile($username)

Hyphens in SlugField

自闭症网瘾萝莉.ら 提交于 2019-12-25 08:16:04
问题 There is a strange error when i open a URL with hyphens in the slug, though SlugField supports hyphens in it as indicated in documentation. So, this is the error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8003/dumpster-rental-prices Using the URLconf defined in dumpster.urls, Django tried these URL patterns, in this order: ^admin/ ^(?P<slug>\w+)/$ The current URL, dumpster-rental-prices, didn't match any of these. If i change the slug of the article to dumpster

Slug not generated when persisting Entity to Database

醉酒当歌 提交于 2019-12-25 03:08:18
问题 I'm using DoctrineExtensions and followed the docs. I have my Entity field decorated with the Sluggable annotation: use Gedmo\Mapping\Annotation as Gedmo; . . . /** * @Gedmo\Slug(fields={"city"}, updatable=false) * @ORM\Column(length=255) */ private $slug; When I try to persist a new entity I get an SQL error: Persist: $em = $this->getDoctrine()->getManager(); $em->persist($location); $em->flush(); Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'slug' cannot be null

Redirect slug, replace plus for dashes

邮差的信 提交于 2019-12-25 02:39:06
问题 I have a rewrite question. It drives me crazy. I created a new website in worpdress. I want to redirect old urls (that are in google) to the new urls. That works fine except for the following urls (there is a plus in the old url) www.domain.com/slugname/this+is+a+slug Has to be rewritten to: www.domain.com/slugname/this-is-a-slug How to replace the plus for a dash (.htacces? add_rewrite_rule?) Sombody has example code? I tried .htacces an add_rewrite_rule in worpdress, but im not smart enough

Multiple hyphen handling in .htaccess (URL rewriting)

陌路散爱 提交于 2019-12-24 17:46:00
问题 I have a problem with URL rewriting. I have written the following rule in my .htaccess file RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2 It gives me URLs like that : http://localhost/actuco/c-628Y8x-france/ (featuring the ID of the category, and its slug). This URL works perfectly. But, when I type this URL : http://localhost/actuco/c-xpS3cc-amerique-du-nord/ it doesn't works anymore. The cause of the problem must be the fact that the latter slug contains several hyphens (amerique

What I need to do in order to open URLs with special characters

折月煮酒 提交于 2019-12-24 08:29:33
问题 Hi i am trying to make a seo friendly url using php. I am using the follwoing code to converting the url like exapmle.com/post/hi-how-are-you and also using this .htaccess code RewriteRule ^post/([\w-]+)/?$ single_post.php?blog_title=$1 [L,QSA] php slug url function url_slug($str) { $str = mb_strtolower(trim($str), 'UTF-8'); $str = preg_replace('/[[:^alnum:]]/iu', ' ', $str); $str = trim($str); $str = preg_replace('/\s+/', '-', $str); return $str; } But the problem is special character. For

How to validation slug in laravel 5.4.24

无人久伴 提交于 2019-12-24 06:58:06
问题 How to create unique slug in laravel and validate them ? Here is my validation code: $this->validate($request,[ 'company_name' => 'required|unique:admin_users,company_name,slug|max:191', ]); Here is my slug code: $db_filed->company_name = str_slug($request->company_name, '-'); Thanks. 回答1: Setup a FormRequest to do the validation for the route with the rules like this: https://laravel.com/docs/5.4/validation#form-request-validation public function rules() { return [ 'company_name' =>

Yii - Make a string usable in a URL or filename

情到浓时终转凉″ 提交于 2019-12-24 02:56:05
问题 Does the Yii framework contain a function that can make a string usable in a URL or filename ? For example: Health+%26+Safety+franchises = health-safety-franchises So something similar to: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#slugify 回答1: slugify in Django Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace. Following are the functions in PHP to carry out same