I have following URL rule in my configuration file:
'rules' => [
'http://<store_url:\w+>.example.com/<product_name:\w+>' => 'index/index'
]
I type http://mystore2.example.com/iphone-15 and I got 404 error. What am I doing wrong?
try this after the last slash \w+(-\w+)+ to match hyphenated words. It could be 'http://<store_url:\w+>.example.com/<product_name:\w+(-\w+)+>' Let me know if it worked
Related
I can upload and see images by admin panel in back-end application without any problems and see images in the "frontend" yii2 application also, but I have an additional separate front-end application and I can't see images there. It's returns 404 error.
Take one image, for example, that has one URL in all applications, but all applications have different domain names.
My common/config/main.php :
'modules' => [
'yii2images' => [
'class' => 'rico\yii2images\Module',
//be sure, that permissions ok
//if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
'imagesStorePath' => '#root/upload/store', //path to origin images
'imagesCachePath' => '#root/upload/cache', //path to resized copies
'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
'placeHolderPath' => '#root/upload/store/no-image.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
'imageCompressionQuality' => 85, // Optional. Default value is 85.
]
Same code of Costa-Rico/images in all 3 models:
public $gallery;
public $gallery_url;
public function behaviors()
{
return [
'image' => [
'class' => 'rico\yii2images\behaviors\ImageBehave',
]
];
}
In the separate frontend application I trying to show image by with code:
$general_logo = General::find()->where(['index' => 'logo_social'])->one();
if($general_logo) $image = $general_logo->getImage();
if($general_logo && $image) : ?>
<meta property="og:image" content="<?= $image->getUrl(); ?>"/>
<?php endif; ?>
I was trying to use frontend\models\General and creating of own this_separate_application\models\General (ActiveRecord, same table) for this application.
How I can to solve this problem? Thank you.
If I understand correctly, you want to access an image from the back-end in the front-end. And they both have different domains. If that is indeed the case, you can just do this in the front-end, while replacing BACKEND_URL with the URL of the back-end. Let me know how it goes.
<meta property="og:image" content="<?= BACKEND_URL . $image->getUrl(); ?>"/>
I find the mistake. It was the stupid problem in the routing of my additional application. In the file separate_application/config/main.php:
'urlManager' => [
'rules' => [
[
'pattern' => '<url:.+>',
'route' => 'page/view',
],
],
]
This rule sent all URL patterns, that don't fit previous rules, to the controller PageController that is responsible for display of separated text pages. PageController also returned 404 page. In this way, it captured URL before it was processed by extension CostaRico/yii2-images and sent the script wrong way. This rule was deleted. Everything is ok with images now!
When I try to upload an image within Laravel the validation is not working. Here my validation string...
'cover' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
The validation error I get is The cover must be an image. It does work however when I only have the required rule.
What is the problem?
You can remove the rule 'image' on your validation :
'cover' => 'required|mimes:jpeg,png,jpg,gif,svg|max:2048',
Hope it help u :)
try this
'cover' => 'required|image|max:2048',
In my project I used an image cropper widget. I setup the widget, that it save in frontend/web/upload. But in backend I save the images to frontend too.
This is working perfect. Then i want to show the image on the backend, if its exist. And i want to reach the frontend.
Thats why i want to set my own aliases in params-local.php file.
But I using vhosts to my webpages and I want to set Aliases to them.
In Yii2 documentation i found an article from aliases, but it wont help me. I mean i tried to use but it wont work.
I tried this:
return [
'aliases' => [
'#front' => 'http://front.mypage.dev',
'#back' => 'http://back.mypage.dev',
],
];
And I also tried this aswell:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
But when i try to echo Yii::getAlias('#front'); it sais
Invalid Parameter – yii\base\InvalidParamException
Invalid path alias: #front
Maybe someone has a solution for this?
Thanks a lot.
Add in backend/config/params.php like:
return [
'front' => 'http://front.mypage.dev',
'back' => 'http://back.mypage.dev',
];
and use it from:
Yii::$app->params['front']
Yii::$app->params['back']
Let me know your thought.
Try this:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
echo Yii::getAlias('#front');
echo Yii::getAlias('#back');
echo Yii::getAlias('#frontend/path/to/file');
echo Yii::getAlias('#backend/path/to/file');
Yii2 Playground
setting-aliases-in-yii2-within-the-app-config-file
I have implemented project using Yii framework. URL manager works fine but. i need to change the URL text. it could be shown domain name after the category name. ie my project URL is kitchenking.com. After the domain name my category name should be display.
ie kitchenking.com/Thanksgiving. But my project url display like this i shows follow:
http://kitchenking.com/recipe/index1/name/Thanksgiving
i did my config file shows following. please suggest me where needs to change the code.
'Home'=>'site/index',
//'cuisine'=>'recipe/index3',
'cuisine/<name:\w+>/<id:\d+>/'=>'recipe/index3',
'holidays/<name:\w+>/<id:\d+>/'=>'recipe/index1',
'calories/<name:\w+>/<id:\d+>/'=>'recipe/index2',
'recipeshow/<name:\w+>/<id:\d+>/'=>'recipe/recipeshow',
//'recipeshow'=>'recipe/recipeshow',
'recipeshow/<name:\w+>/<id:\d+>/'=>'index.php/recipe/course',
above code. i wants to be change like this. recipe/index3 instead cuisine,
recipe/index2 instead holidays,
In UrlManager modify the rules as follows :-
'urlManager' => array(
'rules' => array(
'cuisine' => 'recipe/index3',
'holidays' => 'recipe/index3',
)
)
I'm trying to match this URL:
http://www.example.org/en/site/page/id/1
with these rules:
'rules'=>array(
'/'=>'site/index',
'<lang>/<controller:\w+>'=>'<controller>/index',
'<lang>/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<lang>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>/<id>',
'<lang>'=>'/',
),
I think it's valid but it does not work.
Your url contains an "id" string/text http://www.example.org/en/site/page/id/1 which is not required...
Try url with
http://www.example.org/en/site/page/1
Or append one more route as
'<language:\w+>/<controller:\w+>/<action:\w+>/id/<id:\d+>' =>'<controller>/<action>/<id>',
It should work both ways..
Looks like the language parameter routing is not in the correct format. Try this:
'rules' => array(
'/' =>'site/index',
'<language:\w+>/<controller:\w+>' =>'<controller>/index',
'<language:\w+>/<controller:\w+>/<action:\w+>' =>'<controller>/<action>',
'<language:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' =>'<controller>/<action>/<id>',
'<language:\w+>' =>'/',
),
Try moving the more specific rules to the top.
'rules'=>array(
'<lang:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>/<id>',
'<lang:\w+>/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<lang:\w+>/<controller:\w+>'=>'<controller>/index',
'<lang:\w+>'=>'/',
'/'=>'site/index',
),
[edit] fixed lang regex *credits to Moz Morris.