Zend Implementing SEO friendly or vanity URLs with router - zend-framework

I have a simple e-commerce web application with product URL's like:
http://www.example.com/product/view/product_id/15
where "Product" is the controller and "view" is the action in the Product Controller
How do I change this URL to show up as:
http://www.example.com/product/view/product_name/iphone-4S-16-gb
where product_id "15" is the primary key in the product table and product_name has the value "iphone 4s 16 gb" without the hyphens
What is the simplest way for me to make this change.
Would really appreciate your help.
Thanks a lot.

resources.router.routes.view-article.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.view-article.route = "articles/(?!archive)([a-zA-Z\-]+)/(\d+)(?:/(.*))?"
resources.router.routes.view-article.reverse = "articles/%s/%d/%s"
resources.router.routes.view-article.defaults.module = "articles"
resources.router.routes.view-article.defaults.controller = "view"
resources.router.routes.view-article.defaults.action = "view-article"
resources.router.routes.view-article.map.1 = topicSlug
resources.router.routes.view-article.defaults.topicSlug = topicSlug
resources.router.routes.view-article.map.2 = id
resources.router.routes.view-article.defaults.id = 0
resources.router.routes.view-article.map.3 = articleSlug
resources.router.routes.view-article.defaults.articleSlug = articleSlug
links like http://example.com/articles/circus/616/4-marta-vse-za-ruletkami
http://example.com/products/category/product_id/product_name
EDIT 1
this is a setup for default router plugin. shown as articles from my blog module, but easily updates for shop.
parts - http://example.com/ is host :) articles/circus/ => module and controller mapeed.
resources.router.routes.view-article.map.1 = topicSlug is a category. for shop.
616/4-marta-vse-za-ruletkami ID and any slug. product description, for example, 'iphone-4S-16-gb
'
defaults are in config.
another example /{maps2module}/{maps2topicSlug}/{maps2id}/{maps2articleSlug}

Related

TYPO3 direct_mail_subscription Double-Opt-In-Out not activ

I am using extension direct_mail and direct_mail_subscription for newsletter. In the settings it is clear that i should first confirm the address, so the adress should be in the database as hidden.
// Create setup
create = 1
create {
userFunc_afterSave = EXT:direct_mail_subscription/pi/class.dmailsubscribe.php:user_dmailsubscribe->saveRecord
preview = 0
// add captcha, if you use captcha
fields = gender, name, hidden, email, module_sys_dmail_category, module_sys_dmail_html
required = gender, name, email
noSpecialLoginForm = 1
# Initially hide the user until he approves!
overrideValues.hidden = 1
evalValues.email = uniqueLocal, email
}
so the field hidden in the database should be in the begining 1, however, all data are set to 0 without confirming the address.
Typo3 Version 8.7.2. What should the reason be? Do you have an idea?
Make sure that you have included the static TypoScript template in your own TypoScript template:
You can verify that it is included in the TypoScript Object Browser:

Secondary Table Attributes in Create / Edit Views for primary models

I want to be able to create and edit the secondary table attributes (the relational table) of a many-to-many relationship during the creation or editing of either of the primary tables. So, when I edit one of the primary tables and add a relation to another model (implicitly using the secondary table), I want to be able to access / edit the attributes of that secondary relationship.
More specifically:
Models
# "Primary" table
class Paper(db.Model):
__tablename__ = 'papers'
...
chapters = db.relationship(Chapter, secondary="chapter_paper")
...
# "Primary" table
class Chapter(db.Model):
...
papers = db.relationship('Paper', secondary="chapter_paper")
...
# "Secondary" table
class ChapterPaper(db.Model):
__tablename__ = 'chapter_paper'
paper_id = db.Column(db.Integer,
db.ForeignKey('papers.id'),
primary_key=True)
chapter_id = db.Column(db.Integer,
db.ForeignKey('chapters.id'),
primary_key=True)
### WANT TO EDIT
printed = db.Column(db.Boolean, default=False)
note = db.Column(db.Text, nullable=True)
### WANT TO EDIT
paper = db.relationship('Paper',
backref=db.backref("chapter_paper_assoc",
lazy='joined'),
lazy='joined')
chapter = db.relationship(Chapter,
backref=db.backref("chapter_paper_assoc",
lazy='joined'),
lazy='joined')
So, for this example, I want to be able to edit the "printed" and "note" attribute of ChapterPaper from the create / edit forms of Paper and Chapter in flask admin.
ModelViews
# MainModelView subclasses flask_admin.contrib.sqla.ModelView
class PaperModelView(MainModelView):
...
form_columns = (
'title',
'abstract',
'doi',
'pubmed_id',
'link',
'journals',
'keywords',
'authors',
'chapters',
)
# Using form_columns allows CRUD for the many to many
# relation itself, but does not allow access to secondary attributes
...
So, I honestly have very little idea of how to do this. If I added the form fields as extras and then manually validated them...? (I don't know how to do this)
Even then, adding extra fields to the form doesn't really cover multiple models. Can anyone show me how to do this, or point me to a tutorial / even a relevant example from code that's part of some random project?
Thanks!
Alrighty, this was a lot of work and required a lot of RTFM, but it was pretty straightforward once I got going.
The way to do this without a neat API is to extend the model view and replace the create / edit form with a form of your own.
Here is my form class:
class ExtendedPaperForm(FlaskForm):
title = StringField()
abstract = TextAreaField()
doi = StringField()
pubmed_id = StringField()
link = StringField()
journals = QuerySelectMultipleField(
query_factory=_get_model(Journal),
allow_blank=False,
)
issue = StringField()
volume = StringField()
pages = StringField()
authors = QuerySelectMultipleField(
query_factory=_get_model(Author),
allow_blank=False,
)
keywords = QuerySelectMultipleField(
query_factory=_get_model(Keyword),
allow_blank=True,
)
chapters_printed = QuerySelectMultipleField(
query_factory=_get_model(Chapter),
allow_blank=True,
label="Chapters (Printed)",
)
chapters = QuerySelectMultipleField(
query_factory=_get_model(Chapter),
allow_blank=True,
label="Chapters (All)",
)
The important part for making this functionality happen is the on_model_change method, which performs an action before a model is saved.
...
def on_model_change(self, form, model, is_created):
"""
Perform some actions before a model is created or updated.
Called from create_model and update_model in the same transaction (if it has any meaning for a store backend).
By default does nothing.
Parameters:
form – Form used to create/update model
model – Model that will be created/updated
is_created – Will be set to True if model was created and to False if edited
"""
all_chapters = list(set(form.chapters.data + form.chapters_printed.data))
for chapter in all_chapters:
if chapter in form.chapters_printed.data: # if chapter in both, printed takes priority
chapter_paper = ChapterPaper.query.filter_by(chapter_id=chapter.id, paper_id=model.id).first()
if not chapter_paper:
chapter_paper = ChapterPaper(chapter_id=chapter.id, paper_id=model.id)
chapter_paper.printed = True
db.session.add(chapter_paper)
journal = None
if form.journals.data:
journal = form.journals.data[0]
if journal: # Assumes only 1 journal if there are any journals in this field
issue = form.issue.data
volume = form.volume.data
pages = form.pages.data
journal_paper = JournalPaper.query.filter_by(journal_id=journal.id, paper_id=model.id).first()
if not journal_paper:
journal_paper = JournalPaper(journal_id=journal.id, paper_id=model.id)
journal_paper.issue = issue
journal_paper.volume = volume
journal_paper.pages = pages
db.session.add(journal_paper)
...

Indexed Search Crawler Configuration - Typo3 6.2

I've a custom database table. I want to index the records of the table by
language specific. I've created a crawler configuration named "customindex"
and created a Indexer Configuration named "Data Indexer".
In my website, there are two languages: 0 - Deutch (Default) and 1- English.
But in frontend I can see both Deutch and English records in default
language search. I've investigated with this and I saw a
configuration "tx_crawler.crawlerCfg". (
http://docs.typo3.org/typo3cms/extensions/crawler/ExtCrawler/Configuration/PageTsconfigReference(txCrawlercrawlercfg)/Index.html).
And I don't understand the key parameter here "paramSets.[key]". What is
the "key" actually indicated here? Is it extension key or crawler
configuration name?
I wrote a Page TS config like this;
tx_crawler.crawlerCfg.paramSets.key =
&tx_myext_myext[uid]=[_TABLE:tx_myext;_PID:22;_WHERE:AND
(sys_language_uid=0)]
tx_crawler.crawlerCfg.paramSets.key {
baseUrl = http://www.example.com/
cHash = 1
pidsOnly = 22
procInstrFilter = tx_indexedsearch_reindex
}
# A second tx_tour configuration for another language with language ID 1
tx_crawler.crawlerCfg.paramSets.key =
&tx_myext_myext[uid]=[_TABLE:tx_myext;_PID:22;_WHERE:AND
(sys_language_uid=1)]&L=1
tx_crawler.crawlerCfg.paramSets.key {
baseUrl = http://www.example.com/
cHash = 1
pidsOnly = 22
procInstrFilter = tx_indexedsearch_reindex
}
But I don't know what is that "key" (tx_crawler.crawlerCfg.paramSets.key)
indicated here.
Can you guys please help me to find what is that "key" here?
"Key" will be any variable name we need to use as crawler configuration.

zend Navigation not right work cause zend router

my url is http://mysite.com/index/bytype/id/5/name/ACTION
when using zend router it'll be rewrite to http://mysite.com/index/bytype/5.ACTION.html
i was config in file router.ini like this:
routes.bytype.type = "Zend_Controller_Router_Route_Regex"
routes.bytype.route = "bytype/(\d+).(.*).html"
routes.bytype.defaults.module = "default"
routes.bytype.defaults.controller = "index"
routes.bytype.defaults.action = "bytype"
routes.bytype.map.1 = "id"
routes.bytype.map.2 = "name"
routes.bytype.map.3 = "page"
routes.bytype.reverse = "bytype/%d.%s.html"
code above have issue when i click button next page , it not jump to next page, cause Parameter page/2 not avalable, zend router was rewrite my url become to http://mysite.com/index/bytype/5.ACTION.html again,
if not rewrite it maybe look like http://mysite.com/index/bytype/id/5/name/ACTION/page/2
so how can i including "page" parameter into url above with zend router.thanks for reading
Try Zend routing on your Bootstrap.php file as an alternative.
Here is a tutorial on how to do that:
http://www.codexperience.co.za/post/hiding-url-parameters-names-using-zend-routers

Zend router: combining a list of urls into a single or list

I have several urls:
/dave
/davina
/dave/chris
/davina/peter
I have entries for all of them in my routes, an example of this is:
routes.dave.route = /dave
routes.dave.defaults.module = default
routes.dave.defaults.controller = person
routes.rcp.defaults.action = index
routes.davina.route = /dave/chris
routes.davina.defaults.module = default
routes.davina.defaults.controller = person
routes.davina.defaults.action = index
I think you can see straight away that I have a duplication issue. Is there a way of combining multiple urls into a single route?
I have played around with using /:person but I also have other content aswell not going to person controller.
routes.person.route = /:personname
routes.person.defaults.module = default
routes.person.defaults.controller = person
routes.person.defaults.action = index
routes.person.reqs.personname = "^[a-zA-Z0-9]+$"
Urls such as /search?person=dave which goes off to the search controller is obviously being killed by the expression above.
Can I express the requirement as a list? "dave|davina|etc" or is there another magical zend method of doing this?
UPDATE:
I was playing around and came across this partial solution:
routes.person.route = /:personname
routes.person.defaults.module = default
routes.person.defaults.controller = person
routes.person.defaults.action = index
routes.person.reqs.personname = "(dave|davina)"
routes.person.route = /:person/:personname
routes.person.defaults.module = default
routes.person.defaults.controller = person
routes.person.defaults.action = index
routes.person.reqs.personname = "(chris|peter)"
I am going to run with this for the moment as is satisfies my requirements but I will leave this open(at least for a day) for anyone to offer there advice. The main issues is that both lists are going to grow, which will eventually cause an issue.
I think I may have the anwser for that.
In ZF, the routes are matched in reverse-order. So the last defined route, is the first matched.
In this case, you should define your /:person/:personname route, then define the others static routes like about page, contact page, etc.
If I understand Zend correctly, it should work. This do that in clear:
url=/about
match route "/about"
url=/david/parker
match route "/:person/:personname"
not "/about" or "/contact"