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,
),
Related
I have created CRUD for global configuration parameters. I want to apply this parameters value as main config params (main.php).
I have found some way like add value of these parameters to any .inc file and perform read/write operation. Can anybody help me how can I achieve this? I am beginner in yii.
I have created table structure :
global_config :
Field | Value
pageSize | 20
admin_email| admin#example.com
main.php file as below :
.
.
{
'params' = array(
'pageSize' => 10,
'admin_email' => 'admin#example.com',
);
}
.
.
I am using config file as show above, I want to change it dynamically that it should get value from database.
So that I can make changes in config file from front-end side. I don't need to perform open/write action on main.php
In yii1 you can use params you can set this in main.php
'params'=>array(
'your_param'=>'your_value ',
...
Yii::app()->params['your_param'];
and you can set this value like a simple array poplulating the value form database
$param['yuor_param' =>$your_db_value];
You can't do this for params. As Application parameters are not really meant to be altered and if you change a value, it does not persist across different requests.
These are treated as constant in Yii, So you can't define them after running the script as config files runs at first as your code runs.
Finally, I found solution as per my requirement. I followed given below link from yii forum.
Link : http://www.yiiframework.com/wiki/304/setting-application-parameters-dynamically-in-the-back-end/
Thanks.
I'm using Yii 1.1.15, and am trying to shorted my url's for a module i have. Right now the url are like this
url/alerts/alerts/admin
url/alerts/alerts/create
i'd like to change it to
url/alerts/admin
url/alerts/create
I have this, but doesn't work
'<action:(create|admin)>' => 'alerts/<action>',
Try this :
'alerts/<action:(create|admin)>' => 'alerts/alerts/<action>',
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 am working on cakephp project. I have removed index.php from URL using .htaccess file and now I want to remove view name from URL & add some other two varying parameter. Suppose I choose country & city then these two parameter should appear in URL on selecting them.
The problem I am facing is as cakephp takes
www.example.com/Controllername/viewname
But my requirement is like this
www.example.com/Controllername/param1/param2
If I pass this way It looks for param1 as controller and param2 as view.
Initially should be like:
www.example.com/Controllername/
In your APP/routes.php:
// www.example/com/Controllername
Router::connect('/Controllername',
array('controller'=>'Controllername', 'action'=>'index'));
// www.example.com/Controllername/param1/param2
Router::connect('/Controllername/:param1/:param2',
array('controller'=>'Controllername', 'action'=>'index'),
array('pass' => array('param1', 'param2')));
and your controller:
// set to null/a value to prevent missing parameter errors
public function index($param1=null, $param2=null) {
//echo $param1 . ' and ' . $param2;
}
When generating links:
array('controller'=>'Controllername', 'action'=>'index', 'param1'=>'foo', 'param2'=>'bar');
Order matters. Change paramX to anything you want i.e. country and town
note this does not cover: controllername/param1 - both must be present in this example.
There are other ways to achieve this.
I think you should first make sure that mod-rewrite module is enabled. You shouldn't have had to remove index.php from the url using .htaccess if mod_rewrite were enabled. Check how to enable it in the manual of your webserver and the default .htaccess of cakephp should be able to handle the rest of the routing for you.
After you have enable rewrite module, you can modify the routes as pointed out by #Ross in the previous answer in you APP/routes.php:
// www.example/com/Controllername
Router::connect('/Controllername',
array('controller'=>'Controllername', 'action'=>'index'));
// www.example.com/Controllername/param1/param2
Router::connect('/Controllername/:param1/:param2',
array('controller'=>'Controllername', 'action'=>'index'),
array('pass' => array('param1', 'param2')));
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.