Yii How to render Page NAME instead, ID in URL - yii

I want to render page name through URL request parameter.
like -
r=page/view&name=page_name
instead of id - r=page/view&id=1
please i need to know what i can do in
actionview(), viewfile and urlmanager (code generated by gii)
Help to resolve my issue.

You can do like this -
your request url - r=page/view&name=page
In your action controller -
public function actionView(){
if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){
$page_name = $_REQUEST['name'];
$this->render($page_name);
}
}

Related

Load component/template depending on the route param vuejs

I would like to ask if can I implement this on vuejs, so basically the code will load a page/template base on the param url. I've been searching for a while and can't get the results I need or maybe I'm just searching a wrong keyword.
My url is like this, so I just can't manually declare the url in my route because it is dynamic, fetch from the database.
path: '/user/page_type
Thank you very much!
export default {
mounted () {
if(this.$routes.params.page_type == "home"){
// Load Homepage Here
// ../../../page/HomePage.vue
}
else if(this.$routes.params.page_type == "speaker"){
// Load Speakerpage Here
// ../../../page/HomePage.vue
}
else if(this.$routes.params.page_type == 'html'){
// Load HTML Page Here
// ../../../page/HtmlPage.vue
}
}
}
This is available out of the box within official addon vue-router.
Docs for your case: link

Prestashop - Module, SEO & URL and parameters?

I made a module for Prestashop that will display content based on the given ID in parameter (&id=X).
I'd like to set a nice url for this module.
Using SEO and URLS, I see that it's possible, but it keeps the ?id=X in the url.
For example, if I define the url to my module to be
/pretty-module
I will have the same links but with the different id :
/pretty-module?id=1
/pretty-module?id=23
What I'd like to do, is the following :
/pretty-module => will set id to 1
/even-prettier-module => will set id to 23
I didn't saw a "parameters" options in the SEO & URLS page in the Backoffice, so I'm wondering if it's possible to do this.
you need to hook to moduleRoutes,
1) in your module install method:
if (!parent::install()
|| !$this->registerHook('moduleRoutes')
|| !$this->registerHook('displayFooter'))
return false;
2) creating corresponding hook
public function hookmoduleRoutes($params) {
$routes = array();
$routes['module-examplemodule-handler'] = array(
'controller'=>'handler',
'rule'=>'promo{/:code}',
'keywords'=>array(
'code'=>array(
'regexp'=>'[\w]+',
'param'=>'short_code'
)
),
'params'=>array(
'fc'=>'module',
'module'=>'examplemodule',
'controller'=>'handler'
)
);
return $routes;
}
module may have multi routes.
the convention is module-[MODULE_NAME]-[MODULE_CONTROLLER_NAME]
array explanation:
controller - handler (modules/examplemodule/controllers/front/handler.php)
rule - curly braces are params.. you can get an idea from http://example.com/admin/index.php?controller=AdminMeta
keywords - here you configure your params (curly braces) defined in the rule.
usage example: http://example.com/promo/ADSGD
in controller 'handler':
$short_code = Tools::getValue('short_code');
tested on prestashop 1.6
reference: https://books.google.co.il/books?id=BsSiBQAAQBAJ&pg=PT134&lpg=PT134&dq=prestashop+module+Routes+hook&source=bl&ots=JCb_4oz6el&sig=JwoQfIsOnJ49VJ752fEb01ivMZ8&hl=en&sa=X&ei=vH0QVePiDoXPaNSxgrAP&ved=0CEIQ6AEwBA#v=onepage&q=prestashop%20module%20Routes%20hook&f=false

Rails3: how to reload a page with a parameter taken from a collection_select within the page?

I have a page with a route in the form : :client_id/tarif/:tarif_name
in the corresponding HTML page, I have a <%= collection_select(.....:tarif_name...) which enables to select the name of the tarif to be shown. That works.
How do I instruct to reload the page with the new :tarif_name parameter in the url ?
I thought of using the :onchange option helper with collection_select, but although I managed to execute javascript this way, I find no example of composing and triggering the loading of a url through that option.
Thank you very much for your help
If you are able to run javascript code in the :onchange, then window.location.href = "your_url" will make the redirect.
You will also need the selected value. Your onchange will be something like
function() {
window.location.href = "your_url" + this.value
}

Yii Framework Captcha conflict with beforeAction() function

I have app in Yii and i extend all classes from some base controller and i have these code in it :
protected function beforeAction($action)
{
$this->setglobalvariable();
return parent::beforeAction($action);
}
as i just understand , these code prevent the Captcha to show , because when i delete it , the captcha shows up ! the captcha function is :
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'minLength'=>2,
'maxLength'=>3,
'width'=>60,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
So how could i use beforeAction and captcha in same time ?
The confilict is in your structure , Show us more code . put the program in fresh yii and test it.
beforeAction function , Do not have any conflict with other Yii methods or functions.
The probelm is in your code.
Obviously there is some code in your Controller::setglobalvariables() method that conflicts with the captcha's code.
The CCaptachAction::run() method uses $_GET parameters. Are you somehow resetting $_GET ?
Can you show us the code ?

Yii Controller Parameters

When I create this method
actionTest($parameter){
print($parameter);
}
inside of a yii controller and attempt to access it in the browser I get an error 400.
How can I set up yii so that if I enter:
/controller/test/text it would simply print the string 'text' on the screen instead of returning an invalid request error?
I already verified that the URL is correct. If I write
actionTest(){
print('text');
}
and then go to /controller/test/text then it works just fine.
How can I set up yii so that a controller action can accept parameter values in the URL?
You have to edit the urlManager rewrite rules array in your config.php to include
'urlManager'=>array(
....
'rules'=>array(
'controller/test/<parameter:\w+>' => 'controller/test',
...
),
),
with your controller function as
actionTest($parameter){
print($parameter);
}
#curtis: Thanks. That
helped!!! <controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>
– Curtis Colly Mar 31 '13 at 3:27
The rule <controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action> line will send the last parameter to the controller as $id if you want to use $parameter you should change id to parameter.
<controller:\w+>/<action:\w+>/<parameter:\w+>'=>'<controller>/<action>
In the controller you can also type
actionTest(){
print($_GET['parameter']); //or $_REQUEST
}
Try the url: /controller/test/parameter/text , it should work.
Suggested url rule by #topher is also correct.