I'm using Magento 2 CE Version 2.1.0.
I'm creating a custom module. For saving data I'm using custom INSERT query.
In that INSERT query, i also need to save URL Key/Identifier which is going to display on Browser URL while user access.
URL Key will be a replica of Post Title. Title Contains Example: Hi Can't Save Dat``a.
if (empty($model->getData('url_key'))) {
$urlKey = str_replace(" ", "-", strtolower($model->getData('url_key')));
}
$sql = "INSERT INTO `post` (`title`, `url_key`) VALUES ('" . $model->getData('title') . "', '" . $urlKey . "');";
$connection->query($sql);
In URL Key, we have `, `` or any the characters. What can I use as a function, which Magento uses to store product's URL Key in my Custom Module?
So I don't have to write multiple str_replace
functions.
Thanks