SMS integration in yii - 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 :)

Related

React-Native openURL Twitter Link Issues

I'm displaying a twitter feed in my app which is being pulled in from the twitter API. As the tweets don't show the full text there is a twitter short code URL (t.co) to view the full tweet.
The problem I'm having is when I click the URL using openURL it opens in a browser, which redirects to the twitter app and redirects back to the browser to display the tweet.
This works if I have the twitter app already open - if it's not open the final redirect back to the browser doesn't load the page.
Everything works fine if there's no twitter app installed it just loads in a browser.
Is there a way to avoid the redirects and just have the t.co URLs open in the twitter app if it's installed?
So I managed to solve this issue by first creating a URL unshortener in PHP:
<?php
$url = $_GET['url'];
$context = stream_context_create(
array(
'http' => array(
'follow_location' => false
)
)
);
$html = file_get_contents($url, false, $context);
$final = str_replace("location: ",'',$http_response_header[5]);
echo json_encode ($final,JSON_PRETTY_PRINT);
?>
Then from react-native fetch the full URL from the unshortener:
if (href.contains('https')) {
var short = {
getInfo() {
var myUrl = 'expander.php?url='+href
return fetch(myUrl).then((res) => res.json()).catch(function(error) {
Alert.alert(error+'');
});
}
}
short.getInfo().then((res) => {
var final = res.replace('i/web','web');
Linking.openURL(final);
})
} else {
Linking.openURL(href)
}
It was important to replace 'i/web' in the URL string with 'web' so the app opens the link natively rather than opening a mobile link.

Alias "ext.components.MyClass" is invalid. Make sure it points to an existing PHP file and the file is readable

i am new in yii framework. currently i am using yii 1.1.
now i want to create custom components and we can say than create global function which is use anywhere in the application.
According to this url 'http://www.yiiframework.com/wiki/727/updated-how-to-create-call-custom-global-function-in-whole-application/'
i am follow all steps according to above url
but i have occur a error
Alias "ext.components.MyClass" is invalid. Make sure it points to an existing PHP file and the file is readable.
MyClass.php in the components folder
class MyClass extends CApplicationComponent {
public function get_my_info() {
$value = '1';
return $value;
}
}
Declare in the config folder
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'myClass' => array(
'class' => 'ext.components.MyClass',
),
And use in the view file
<?php
$myInfo = Yii::app()->myClass->get_my_info();
echo $myInfo;
?>
Have you put the file in correct component directory?. As per your alias the path should be /protected/extensions/components/MyClass.php
Write full path like application.modules.setting.components.*

View PDF in Yii

I have PDF stored in a folder, now i want to view it via link on my form page. How will i do it using Yii framework.
echo CHtml::link(
'pdf',
Yii::app()->createUrl('/uploads/Tutorial.pdf') ,
array('class'=>'button','target'=>'_blank'));
The error i am receiving mentioned below, i have also tried by including uploads in allow of controller.
Error
Error 404
Unable to resolve the request "uploads/Tutorial.pdf".
I am using mPDF to generate PDF but i don't know how to view an already generated PDF using Yii.
You need several more things to make this work. You may have already done some of this and not pasted it but here goes...
I'm assuming you've set up your site to use clean URLs with .htaccess by following this tutorial. Now you can add:
in config/main.php, urlMananger section you need a route to a controller class and action method. This tells Yii which controller to use when you go to the URL /uploads/Tutorial.pdf
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'uploads/<filename:[a-zA-Z]+\.pdf>' => 'upload/viewPdf', // actionViewPdf Method in UploadController class
// ... all your other rules
),
),
And a controller class, and a method with the same name as in your route above (prepended with action):
class UploadController extends Controller
{
// Put the usual Yii access control stuff here or whatever...
public function actionViewPdf()
{
$filename = $_GET['filename'] . '.pdf';
$filepath = '/path/to/your/pdfs/' . $filename;
if(file_exists($filepath))
{
// Set up PDF headers
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($filepath));
header('Accept-Ranges: bytes');
// Render the file
readfile($filepath);
}
else
{
// PDF doesn't exist so throw an error or something
}
}
}
Then you should be able to use
echo CHtml::link(
'pdf',
Yii::app()->createUrl('/uploads/viewPdf', array('filename' => 'Tutorial')) ,
array('class'=>'button','target'=>'_blank'));
Hope that's helpful.
Well.... are you sure that the uploads folder is available on the server and it is in a location that is link friendly? Yii does not pass everything through it's index.php file, if a file already exists then it just used it like it is. That is why you can access the files in your images or css folder without having a controller for it.
If you are using the normal Yii structure then you should have your "uploads" folder next to your protected folder.
If your uploads folder is not in a web accessible location, use what JamesG told you to. The only change I would to is to the pattern, it only matches letters, you might have other chars in the name too.
Do not add ".pdf" to your link:
Yii::app()->createUrl('/uploads/Tutorial')
in PHP you can print your pdf like this (must be in the actionTutorial):
$mPDF = Yii::app()->ePdf->mpdf();
$mPDF->WriteHTML($this->render('tutorial', array(), true));
$mPDF->Output();
The tutorial is a simply html page that should be rendered into your pdf.
Here you can find the doku to the mpdf Yii extension

rails 3.x pageless callback method

I am working on integrating jquery pageless plugin with a rails application. The pageless plugin works seamlessly when i write out the javascript. The issue lies in trying to have a javascript method issued upon complete. What i am trying to accomplish is having a helper method to generate it, but it renders the javascript with quotes around my callback method which then generates an error in the javascript
Uncaught TypeError: Object reloadMasonry has no method 'call'
here is the helper method code
def pageless(total_pages, url=nil, container=nil) opts = {
:totalPages => total_pages,
:url => url,
:loaderMsg => 'Loading more results',
:loaderImage => image_path("load.gif"),
:complete => "reloadMasonry"
}
container && opts[:container] ||= container
javascript_tag("$('#masonry-container').pageless(#{opts.to_json});")
end
This is the produced javascript code
<script type="text/javascript">
//<![CDATA[
$('#masonry-container').pageless({"totalPages":3,
"url":"/articles",
"loaderMsg":"Loading more results",
"loaderImage":"/assets/load.gif",
"complete":"reloadMasonry"});
//]]>
</script>
the javascript results in having quotes around the reloadMasonry callback function
reloadMasonry = function(){
$('#masonry-container').masonry('reload');
}
if i copy the exact javascript produced, and simply remove the double quotes around the javascript callback method ( reloadMasonry ) in this case, everything works seamlessly.
does anyone have any suggestions.

Using AngularJS within Haml views of a Rails app

I have a Rails app with Haml views. Now I want to add AngularJS to some parts of the application, but the problem is that the Haml views are rendered server-side and the AngularJS code is not working, because it is rendered client-side.
Let's say I have just this in my index.html.haml:
!!!
%html{"ng-app" => "Test"}
%head
%script{:src => "http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"}
:javascript
function Clock($scope) {
$scope.currentTime = new Date();
}
%title Welcome to AngularJS
%body
%h1 Hello, World.
%p{"ng-controller" => "Clock"}
The current time is {{currentTime | date:'h:mm:ss a'}}.
So currently, it's just printing out everything within the curly brackets without actually processing it. There are solutions but they for situations where your complete view is replaced by an AngularJS template. I want to use AngularJS mainly for small bits of functionality in my Rails app. Any ideas how to solve this?
John,
I have edited your code a bit here: http://codepen.io/anon/pen/vKiwH
%html{"ng-app"=>true}
%p{"ng-controller" => "clock"}
The current time is {{currentTime | date:'h:mm:ss a'}}.
and the javascript is:
function clock($scope) {
$scope.currentTime = new Date().getTime();
}