yii url manager - php

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.

Related

Yii2 URL is not working

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

Yii URL flow manager issue with Yii infinite scroll

I have implemented project in Yii. I done Yii infinite scroll extensions. its working fine. but configure the URL management in Yii. its also working fine. am facing issue is. i am printing values is 10 per page Size. so, that values are repeating continues.
my config page is
'holidays/<name>'=>'recipe/index1',
'calories/<name>'=>'recipe/index2',
),
'showScriptName'=>false,
above code if i remove the . the URL will be show like this.. and lazy loader not repeating the values ie working fine.
recipe/index2/name/Chinese
i want to display like this
/Cuisine/Chinese
and also not reapting the page values. please help how to solve these issue
http://www.yiiframework.com/doc/guide/1.1/en/topics.url if you didn't see this document: you can create an url pattern or write your own UrlRule class. For your example something like
array(
'/Cuisine/<name:\w+>'=>'recipe/index2/name/<name>',
)
'urlManager'=>array(
'urlFormat'=>'path',
// 'useStrictParsing'=>true,
// 'appendParams'=>true,
'rules'=>array(
// '<view:about>'=>'site/page',
'' => 'site/index',
// 'Home'=>'site/index',
//'cuisine'=>'recipe/index3',
// 'Cuisine:/'=>'recipe/index3',
// 'Cuisine/'=> 'recipe/index3',
'Cuisine/<name>'=>'recipe/index3',
// '1'=>'recipe/index3',
'2'=>'recipe/index1',
'3'=>'recipe/index2',
//'holidays/<name>'=>'recipe/index1',
//'calories/<name>'=>'recipe/index2',
'recipes/<name>'=>'recipe/recipeshow',
'advancedsearch'=>'recipe/newadv',
// 'advancedsearch/<name>'=>'recipe/advancesearch1',
// 'search'=>'recipe/course',
// '4'=>'recipe/course/',
'5'=>'recipe/advancesearch1',
),
//'appendParams'=>false,
'showScriptName'=>false,
// 'caseSensitive'=>true,
),

Wordpress rewrite rules and custom optional arguments in url

I am trying to build a filtering functionality for a Wordpress website using add_rewrite_rules. I have the following link example
example.com/offers-type-all-inclusive-from-germany-transportation-airplane.html
Using the following rewrite rule:
add_rewrite_rule('^offers-type-?([a-z0-9-]+)?-from-?([a-z-]+)?-transportation-?([a-z0-9-]+)?.html','index.php?filters=offers&type=$matches[1]&location=$matches[2]&transportation=$matches[3]','top');
I managed to redirect the user to a custom page template with the arguments stored as an array
array(
'type' => 'all-inclusive',
'from' => 'germany',
'transportation' => 'airplane'
);
The problem is that some of the arguments could be optional so that links like
example.com/offers-type-all-inclusive-from-germany.html
example.com/offers-type-all-inclusive-transportation-airplane.html
also need to build the correct filtering array.
Is it even possible to achieve this?
What a tricky regex!
Try this expression
offers-type-([a-z0-9-]*?)(?:-from-([a-z-]*?))?(?:-transportation-([a-z0-9-]*?))?\.html
Here is an online demonstration
http://regex101.com/r/fS4xB7

url management flow in yii framework

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',
)
)

Check for posted data inside the config file or form_validation.php in CodeIgniter

I want to check for a posted data if present so that I can set a form field as required or not, without having to create a custom rule.
Is it possible to use/load/call CodeIgniter's input library inside the config file (specifically the form_validation.php config file) and get user posted data without having to use the native $_POST variable?
my code goes something like this...
...
array(
'field' => 'dob_day',
'label' => 'Day',
'rules' => (($this->ci->input->post('include_person') === 'yes') ? 'required|' : '') . 'integer|max_length[2]|greater_than[0]|less_than[32]|valid_birth_date'
),
...
Obviously, my approach does not work. hehe. If there's an alternative efficient codeigniter way of doing what i'm thinking, please let me know.
Thanks for all your help! :)
See this:
MANUAL
try this example, in this mode you can at runtime change your rules:
$this->form_validation->set_rules('dob_day', 'Day', 'your new rules');
Okay, I ended up with putting the logic in the controller, and just using inline validation. But to have inline validation work without having to set all the rules, I used the code from this website to allow both inline and config rules to mix.
http://brettic.us/2010/09/13/codeigniter-form-validation-mix-rule/
Cheers!

Categories