How to use a fetch in CakePHP 2? - cakephp-2.0

How to use a fetch in CakePHP 2?
The default action for the connection using
echo $ this-> fetch ('content');
And how to use the fetch include leftmenu.ctp?
So do not get
echo $ this-> fetch ('leftmenu');

you should use leftmenu as an element. In Elements folder place the ctp file and include it like this:
echo $this->element('leftmenu');

Related

How to Disable Direct file Download via .htaccess

I want to disable direct file download to my .zip files.
If my website is the referrer then only download the file.
I am using Apache server
You can try this one which will help you but I will suggest you to research more on this.However you can put the below code for the work.
Also make changes to the below code for the changes.
<?php
// This is to check if the request is coming from a specific domain domain.com
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
if($refData['host'] !== 'domain.com') {
// Output string and stop execution
die("Hotlinking not permitted");
}
echo "Executing code here";
?>
You need to change your domain above eg. clubapk.com instead of domain.com

angularjs state.go doesn't reload php file

I have a code which uses ui-router. It is navigating in 2 files(state). 1 is the php file which displays all the contents of an SQL db, while the other is an HTML file retrieving data from 1 row of the SQL db.
The php file is getting the contents of the db using
$inbox = mysql_query("SELECT * FROM wps LIMIT $offset,$limit");
$rows = mysql_num_rows($inbox);
while($row = mysql_fetch_assoc($inbox)){
$id = $row['id'];
$RDate = $row['RDate'];
echo '<tr class="border_bottom">';
echo '<td>'.$id.'</td>';
echo '<td>'.$RDate.'</td>';
echo '</tr>';
The html file is accessed by an ng-click which transfers the user in to this state and is getting the details of the SQL db row using $http.post method from a js file.
After editing the row of the SQL DB by using the HTML file, I will have to go back to the php file using $state.go. But after returning to the php file, the changes are still not reflecting.
I already tried using
$state.go('phpstate',{}, {reload:'phpstate'});
to refresh the rows displayed but it doesn't really work.
Please check the below code
$state.go($state.current, {}, {reload: true});
Reload option parametr is boolean. Maybe you must try it:
$state.go('phpstate',{}, {reload:true});

CakePHP Upload Plugin: Programmatic File Retrieval without a Form

I use CakePHP-Upload plugin, now need to use the upload without form, following this example: Programmatic File Retrieval without a Form
All my upload are stored in the associated model, called the Attachment.
So when I save the article, at the same time save the images in Attachmen model.
Plugin documentation suggests something like this:
<?php
$this->Article->set(array('file' => $image_path)); // ?????
$this->Article->save();
?>
I have a larger collection of images on the server, previously uploaded via the Joomla CMS, now I have a migration of data to a custom CMS built on CakePHP framework. I need to take all these pictures and upload again, through this plugin.
How to properly use this plugin for my needs, I try to put the path to a local picture, but uploading is not working ???
EDIT
$image_path = WWW_ROOT . 'img' . DS . 'attachment' . DS . '59'.DS.'hpim4799.jpg';
debug($image_path);
'C:\xampp\htdocs\portal\webroot\img\attachment\59\hpim4799.jpg'
Do not save the record and not create new images.
Note, uploading through HTML form works well, I use windows 7 and xampp server.
EDIT 2 / Solution
Image path must be valid url like 'http://localhost/portal/img/attachment/59/hpim4799.jpg'
$image_path = Router::url('/', true) . 'img/attachment/59/hpim4799.jpg';
Thank you.
Can you tell me what the content of the variable $image_url is? The doucmentation says you can add a file via the form, or you can do it programmatically. If you do that, use the $image_url as path to the image. If you got an associated model like Attachment you shoud use:
<?php
$this->Article->set(array('Attachment.file' => $image_path)); // path + file to file
$this->Article->save();
?>
After hours of searching for solutions and detailed inspection of the Behavior code I finally found it.
Because Behavior uses php FILTER_VALIDATE_URL Filter, path must be a valid URL. Here is an example:
<?php
$image_path = Router::url('/', true) . 'img/attachment/59/hpim4799.jpg';
// return http://localhost/portal/img/attachment/59/hpim4799.jpg
$this->Article->Attachment->set(array('file' => $image_path));
$this->Article->Attachment->save();
?>

Cakephp custom config file

Basically I want to create file in Config folder, for example app/Config/emailProvider.php where I can save name of the class to instantiate.(Something similar to database.php)
The problem is I don't know how to load file, I've tried with
Configure::config('email', new PhpReader());
Configure::load('emailProvider', 'default')
but I always get an error CORE/Cake/Core/Configure.php line 298 → PhpReader->read(string)
Well, first of all, let's assume that your config file app/Config/emailProvider.php contains the following contents:
<?php
$config['MyTestApp']['email'] = 'bob#gmail.com';
.....
Next thing is that you need to tell your app to load the custom config file by including it in bootstrap.php inside app/Config:
Configure::load('emailProvider');
Then, you can access it from your controller as below:
$email = Configure::read('MyTestApp.email');
Reference link

Replace php file include after form action with next include

How can i include a php file after form action POST? All of the file must be loaded on the same page.
What i have:
if ($_POST['vaste_kosten'] > 0) echo "<form method='post'action='mail.php'>
I don't like the iframe function in HTML to do this.
How can i include a php file after
form action POST
you can use include_once, include, require , require_once whichever you prefer
if (isset($_POST['submit']))
{
include('file.php');
include('anotherfile.php');
}
I'm not sure if this is what you mean, but it certainly answers what you're asking. You should simply use the include function, as follows:
if ($_POST['vaste_kosten'] > 0) {
echo "<form method='post'action='mail.php'>";
include("path_to_file/file.php");
...
}

Resources