How to add .html end of URL - phalcon

I'm new with Phalcon PHP. I can't figure out how can I add .html to end of url for every page. I already looked up docs. Nothing related to this isn't in docs
Thanks,

You can customise the routing parameter, e.g:
$router->add(
"/documentation/{name}.{type:[a-z]+}\.html",
array(
"controller" => "documentation",
"action" => "show"
)
);
would route /documentation/color.doc.html to showAction in DocumentationController with params $this->dispatcher->getParam("name") === "color" and $this->dispatcher->getParam("type") === "doc"
For further info please read the docs in http://docs.phalconphp.com/en/latest/reference/routing.html

Related

a route doesnt work (yii)

Hy stackoverflow !
I'm trying to make a form into an external page with Yii 1.1.14 (this is an old site).
I've made a directory into my views call signinPartners and into this one, a php file call signin.
I have also created a controller :
class SigninPartnerController extends Controller
{
public function actionSignin(){
$this->render('/signin');
}
}
He renders the route /signin defined in my config by :
return array(
'' => 'index',
'signin' => 'signinPartners/signin',
);
but when I try the URL http://mylocalserver/signin the site send back Error 404 Unable to resolve the request « signin-partners/signin »..
This is really disturbing because there are other URL's on my website and they work the same way without throwing an error 404. I don't know what I missed... Can somebody help ?
my urlManager :
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false, // do not display index.php in the url
'urlSuffix' => '/',
'rules' => $routesRules, //this variable contains the array defined above
),
I have also check my runtime :
2018/01/17 11:12:16 [error] [exception.CHttpException.404] exception 'CHttpException' with message 'Impossible de résoudre la requête « signinPartners/signin ».' in D:\Windows\Windows\CommonFiles\wamp64\www\MoovTime-Conso\library\Yii\web\CWebApplication.php:286
Stack trace:
#0 D:\Windows\Windows\CommonFiles\wamp64\www\MoovTime-Conso\library\Yii\web\CWebApplication.php(141): CWebApplication->runController('signinPartners...')
#1 D:\Windows\Windows\CommonFiles\wamp64\www\MoovTime-Conso\library\Yii\base\CApplication.php(183): CWebApplication->processRequest()
#2 D:\Windows\Windows\CommonFiles\wamp64\www\MoovTime-Conso\public\frontend\index.php(36): CApplication->run()
#3 {main}
REQUEST_URI=/signin
---
(the exception message is in french and means Unable to resolve the request « signin-partners/signin »)
Ok, big update, i've tried to play with routes.php and I realized that the name of my controller doesn't match with signinPartners. So, I update the routes rules with :
return array(
'' => 'index',
'signin' => 'signinPartner/signin',
);
And now, we have a new error : Controller can't find the view « /signin »..
There is the post Controller can't find the view in Yii which can anwser this question !
ANSWERED
try adding a - in signinPartners.
'signin-partners/signin'
The problem in my case was the action, the directory name in my view that contains the page and the route rule.
first, I update the route rule from :
return array(
'' => 'index',
'signin' => 'signinPartners/signin',
);
to :
return array(
'' => 'index',
'signin' => 'signinPartner/signin', // controlerName/actionName
);
The controller name was wrong.
In a second time, to match with the name of the controller, I simply renamed the directory in views calls signinPartners to signinPartner (only for readability).
Finally I update the action actionSignin that was :
public function actionSignin(){
$this->render('/signin');
}
For :
public function actionSignin(){
$this->render('/signinPartner/signin');
}
Where I change the path with the new directory name.

SMS integration in yii

I am trying to integrate SMS in my web application. I added the code in my last line of function:
header("Location:http://www.bulksmsservice.co.in");
But its not redirecting to that site. (Function is in model page)
If you use the PHP Command header, be sure there is no output before you call it. To do it in the Yii view file is too late. But to do this in the Yii Controller is not a good Practice. Better would be $this->redirect() or in the view File use Javascript Code:
<script>
window.location ='http://www.bulksmsservice.co.in';
</script>
i added my function sendbulk in controller and replace code with below
function sendbulk($num,$msg)
{
$link = "http://www.bulksmsservice.co.in/api/sentsms.php?username=****&api_password=*******&to=".$no."&priority=2&sender=******&message=".$msg. "&unicode=1";
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1
)
)
);
file_get_contents($link, 0, $ctx);
}
Now it's working perfectly for single messages and multiple messages :)

User management hybrid auth setup

I'm trying to setup hybrid auth on the Yii user management addon, the docs are here https://github.com/thyseus/yii-user-management/blob/master/user/docs/hybridauth.txt
according to this step
Take the modules/user/vendors/index.php, rename it to 'hybridauth.php' and place it
beside your application index.php bootstrap script. This will be your hybrid auth
entry script.
for this, there is NO index.php file in modules/user/vendors/index.php but there is one in modules/user/vendors/hybridauth/index.php which i renamed to hybridauth.php and put it in http://localhost/dev/ content of the hybridauth.php are
require_once( "protected/modules/user/vendors/hybridauth/Hybrid/Auth.php" );
require_once( "protected/modules/user/vendors/hybridauth/Hybrid/Endpoint.php" );
Hybrid_Endpoint::process();
now for this
Place the hybrid auth configuration file into your application
protected/config/hybridauth.php.
i took my modules/user/vendors/hybridauth/config.php and put it in protected/config/ and renamed config.php to hybridauth.php. the content looks like this
return
array(
"base_url" => Yii::app()->createAbsoluteUrl('/').'/hybridauth.php',
"providers" => array (
...........
"Google" => array (
"enabled" => true,
"keys" => array (
"id" => "ID",
"secret" => "SECRET",
),
),
"Facebook" => array (
"enabled" => true,
"keys" => array (
"id" => "ID",
"secret" => "SECRET",
),
"scope" => "email,user_birthday" // https://developers.facebook.com/docs/reference/login/
),
),
// if you want to enable logging, set 'debug_mode' to true then provide a writable file by the web server on "debug_file"
"debug_mode" => false,
"debug_file" => "",
);
problem is when i click say on the facebook icon on my login page, it shows my main page. (index.php)
here is the link it directs too
http://localhost/dev/index.php/hybridauth.php?hauth.start=Facebook&hauth.time=1388044835
when i remove the index.php from the url
http://localhost/dev/hybridauth.php?hauth.start=Facebook&hauth.time=1388044835
i get this error
You cannot access this page directly.
any idea what i'm doing wrong? Thanks
This sound like a routing problem in your configuration:
you might want to add a route for hybridauth.php and make sure it is only accessable by GET
for example :
'components'=>array(
......
'urlManager'=>array(
'showScriptName' => false,
'urlFormat'=>'path',
'rules'=>array(
'hybridauth'=>array('user/hybridauth/index', 'verb'=>'GET', 'urlSuffix'=>'.php'),
....
),
),
),
if anyone having the same problem, here is how i solved it:
by changing the base_url to point to the actual php file:
"base_url" => Yii::app()->getBaseUrl(true).'/hybridauth.php',
If you use YUM User Managment try to import
Yii::import('application.modules.profile.models.*');
on YumUserAuthController because profile cannot be found.

Yii url rules for main page

'urlManager'=>array(
'class'=>'application.components.UrlManager',
'urlSuffix'=>'/',
'baseUrl'=>'',
'showScriptName'=>false,
'urlFormat'=>'path',
'rules'=>array(
'<language:\w{2}>' => 'page/index',
'' => 'page/index',
'<language:\w{2}>/page/<alias:.*>' => 'pages/read',
)
link "/en/page/index" works fine
links "/" and "/en" returns the error "Unable to resolve the request" page / index ".
what is wrong with the rules
'<language:\w{2}>' => 'page/index'
'' => 'page/index',
?
UPD:
pagesController has an action:
public function actionRead($alias){
//some php code...
if($model==null)
{
throw new CHttpException(404,'page not found...');
}else
{
$this->render('read',array('model'=>(object)$model));
}
}
Your rules that don't work are redirecting to page/index, meaning that they're going to try and access PageController.php, and within that controller, they're going to try an access actionIndex. It doesn't sound like you have either a controller PageController.php, much less an actionIndex within that controller.
You need to fix the targets of those rules to include valid controller/action combinations.

How to create ajax delete link in CViewList widget in _view file

CGridView widget is already having view,update,dete option.But i am using CListView widget in my jquery mobile based project, but having problem in creating ajax link for delete option. Not getting idea how to create a ajax delete link in _view.php(view file) and its renderPartial() view file to disappear the bar after successfully deleted plz help thanks in advance. Here is the _view.php file link for edit and delete.
<?php
echo CHtml::link(CHtml::encode($data->id),
array('editmember1', 'id' => $data->id),
array('data-role' => 'button', 'data-icon' => 'star')
);
echo CHtml::link(CHtml::encode($data->id), $this->createUrl('customer/delete', array('id' => $data->id)),
array(
// for htmlOptions
'onclick' => ' {' . CHtml::ajax(array(
'beforeSend' => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;else return false;}',
'success' => "js:function(html){ alert('removed'); }")) .
'return false;}', // returning false prevents the default navigation to another url on a new page
'class' => 'delete-icon',
'id' => 'x' . $data->id)
);
?>
This is happening because:
The correct action is not being called, because you have not set the url property of jQuery.ajax(). You should know that Yii's CHtml::ajax is built on top of jQuery's ajax. So you can add :
CHtml::ajax(array(
...
'url'=>$this->createUrl('customer/delete', array('id' => $data->id,'ajax'=>'delete')),
...
))
Also in the url i'm passing an ajax parameter so that the action knows that it's an ajax request explicitly.
Then the controller action by default(i.e Gii generated CRUD) expects the request to be of post type, you can see this in the customer/delete action line:if(Yii::app()->request->isPostRequest){...}. So you have to send a POST request, again modify the ajax options:
CHtml::ajax(array(
...
'type'=>'POST',
'url'=>'',// copy from point 1 above
...
))
Alternatively you can also use CHtml::ajaxLink().
To update the CListView after deletion, call $.fn.yiiListView.update("id_of_the_listview");. Something like:
CHtml::ajax(array(
...
'type'=>'POST',
'url'=>'',// copy from point 1 above
'complete'=>'js:function(jqXHR, textStatus){$.fn.yiiListView.update("mylistview");}'
...
))