How to send a pdf file as attachment in cakephp? [closed] - cakephp

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using cake php 2.0 version, I need to send a PDF attached email once clicked on survey button in my application?
Any help greatly appreciated.

Try this:
First of all, you should ensure the class is loaded using App::uses():
<?php
App::uses('CakeEmail', 'Network/Email');
in your function/action:
$email = new CakeEmail();
$email->attachments('/full/file/path/file.pdf')
$email->to = 'em...#email.co.uk';
$email->subject = 'Something';
$email->replyTo = $client['Client']['email'];
$email->from = $client['Client']['email'];
$email->emailFormat = 'html';
if($email->send()){
die('Email Sent!');
}else{
die('Failed to send email');
}

Related

CakePHP checkbox for values 0 and 1 [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to generate a CakePHP checkbox for a boolean field of my database, but it is resisting. I have tried in many different ways, but it's not working.
The checkbox is always 1, no matter if selected or not.
Any idea what might be the problem?
echo $this->FormTB->input(
'puntuacion',
array(
'checked' => true,
'value' => 1,
'label' => 'Puntuar esta empresa',
'class' => 'checkbox',
'data-id' => 'puntuar'
)
);
I have tried removing the "value" => 1 part, nothing changed.
As already pointed out multiple times in the comment, that is exactly how cakephp operates internally: a "not checked" is internally transferred to a boolean FALSE - which again is equivalent to integer 0 - in the controller/model.
So this suffices:
echo $this->FormTB->input(
'puntuacion', array(
'label' => 'Puntuar esta empresa',
'class' => 'checkbox',
'data-id' => 'puntuar'));
remove the 'checked' => true, 'value' => 1, part

iterate over json in javascript [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Want to iterate over this routes->bounds->legs->steps and alert(path). I am new to use json , can you please tell how to achieve this .thanks in advance.
JSON is --
{"routes":[{"bounds":{"copyrights":"Map data ©2013 Google"},
"legs":["steps":[{"distance":{"text":"1 ft","value":0},
"path":[{"ib":39.049870000000006,"jb":-76.51013}],
"lat_lngs":[{"ib":39.049870000000006,"jb":-76.51013}],
"start_point":{"ib":39.04987000000001,"jb":-76.51013},
"end_point":{"ib":39.04987000000001,"jb":-76.51013}}],
"via_waypoint":[],"via_waypoints":[]}],"status":"OK"}
The first step would be to parse the JSON string you have received.
Then you're able to access all of it's properties via dot notation:
With jQuery you could do it like this:
//{
// "Name": "Apple",
// "Expiry": "2008-12-28T00:00:00",
// "Price": 3.99,
// "Sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}
var json = '{"Name": "Apple","Expiry": "2008-12-28T00:00:00","Price": 3.99,"Sizes": ["Small","Medium","Large"]}';
var obj = jQuery.parseJSON(json);
$.each(obj.Sizes, function(index, item) {
$("body").append("<p>" + item + "</p");
});
Look how I access the Sizes property on the parsed JSON string:
obj.Sizes

In yii how to create retrive fields input and compare it with databse fields [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
In yii i am creating forget password functionality. after clicking on forgetpassword button, server will provide one php paga with blank text field for entering primary email id. Now how to retrive this email id in controller's method and how to check wheather this email id exist in databse. Please help me...
This will help you get started, you would put a method similar to this in your controller and create a view with a password field on it.
public function actionForgotPassword(){
if(isset($_POST['email']{
$record=User::model()->find(array(
'select'=>'email',
'condition'=>'email=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
$error = 'Email invalid';
} else {
$newpassword = 'newrandomgeneratedpassword';
$record->password = md5($newpassword );
$record->save(); //you might have some issues with the user model when the password is protected for security
//Email new password to user
}
}else{
$this->render('forgetPassword'); //show the view with the password field
}
}

Uploading image in database and file directory codeigniter [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
this is my controller main.php this is uploading the file in directory what i want to store the same file name in database and retrieve the image by name. you can tell be the solution code or edit my code really need the code
<?php
class Main extends CI_controller{ // mian controller
function index(){
$this->load->view('main_view.php', array('error'=>''));
}
function upload(){ // upload function for image
$config['upload_path'] = './images/'; //directory
$config['allowed_types'] = 'jpg|jpeg|gif|png';//type allow
$this->load->library('upload',$config);
if(! $this->upload->do_upload()){
$error = array('error'=>$this->upload->display_errors());
$this->load->view('main_view',$error);
}
else
{
//
$file_data = $this->upload->data();
$data['img'] = base_url().'/images/'. $file_data['file_name'] ;
$this->load->view('success_msg',$data);
}
}
}
?>
this is my view main_view.php
<html>
<body>
<? echo $error;?>
<? echo form_open_multipart('main/upload'); ?>
<input type="file" name="userfile" />
<input type="submit" name="submit" value="Upload" />
<?php echo form_close();?>
</body>
</html>
i want to upload file name in database and can easily retrieve the image
You can retrieve the image name wth: $this->upload->file_name
EDIT:
there are some errors in your code.
1) this $this->load->view('main_view.php', array('error'=>''));should be $this->load->view('main_view', array('error'=>''));without the .php extension.
2) CI_controller should be CI_Controller
You can use this simple lines of code to upload a file in a folder and grab the file name and store it in database.
$image_path = '../../test_images/'.$_FILES['question_image']['name'];
if(is_uploaded_file($_FILES['question_image']['tmp_name']))
{
move_uploaded_file($_FILES['question_image']['tmp_name'], $image_path) ;
}
$image_url = "test_images/".$_FILES['question_image']['name'];
$image_path is the url where you want to upload your file and $image_url will contain the url that your are going to store into database
Now you can retrieve the image by
<img src="<?base_url($image_url)?>" />

Model and controller structure in CakePHP [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I Want to separate the database functionality and logic part by having the database operations in the model and the logic part in the controller. Earlier I had all the code in the action part of the controller itself. I have tried something, but it doesn't work.
This is what I had earlier:
/* Controller */
function insertFormName(){
$formname=$_POST['formname'];
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
And now I changed it a bit, which doesn't work:
/* Controller */
function insertformname()
{
$this->data['Form']['formname']=$this->params['form']['formname'];
$this->Form->save($this->data);
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
/* Model */
function save($data)
{
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
return $newid;
}
EDIT:
I have tried it another way.. Have the entire functionality in the model and just call that function from the controller.Is this method correct?
/* Model */
function saveFormName($data)
{
$this->formname=$data[$this->name]['formname'];
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
/* controller */
function insertformname()
{
$this->data['Form']['formname']=$this->params['form']['formname'];
$this->Form->saveFormName($this->data);
}
It looks like you should probably revisit the Cake book (book.cakephp.org) and redo the lessons. If you setup your form correctly, you shouldn't have to manually assign $_POST['formname'] to $this->data. Try setting the field names in your form (in the HTML) to data[ModelName][FieldName].
Next:
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
Why are you updating data right after you saved it? Where do the $newid and $formname variables come from? You have them defined in the Model::save, but not in the controller.
This seems like you're trying to fight with the Cake automagic stuff too much. Perhaps you should repost your question, but please spell out your high level description rather than just a "why doesn't this work?" It looks to me like this could be simplified a ton, but, again, I'm not quite sure what your objectives are.
Respectfully,
Travis

Resources