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});
Related
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();
?>
I use html2pdf, which is based on TCPDF, in CakePhp to render Views in PDF.
However, sometimes the generation hangs, I mean the browser freezes and never receives data.
There is a way to debug such a behavior? In apache logs I do not see any kind of error...
$this->set(compact('quotation','company','user'));
$view = new View(null, false);
$view->set(compact('quotation','company','user'));
$view->viewPath = 'Quotations';
$view->layout = 'preventivo';
if ($quotation['Quotation']['quotation_type'] == SERVICE)
{
$content = $view->render('print_s_template');
$this->set(compact('content'));
$this->response->type('pdf');
$this->render('print');
the print.ctp has
App::import('Vendor', 'HTML2PDF', array('file' => 'html2pdf'.DS.'html2pdf.class.php'));
$html2pdf = new HTML2PDF('P','A4','it');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
and the html is in print_s_template.ctp.
I found a solution myself. The problem is that I forgot to pass some variables to the View $view. And I suppose cake throw an error which, next, html2pdf cannot "render".
So: double check that all the variables in the view do exist!
I'm using Symfony 2.3 and Doctrine 2 and i need that an user save the schema of a Doctrine Database to a file (*.sql). I need it into an action method and then send the file to the user
You need to execute following command:
.app/console doctrine:schema:create --dump-sql >schema.sql
And here's the answer how to run Command from Controller: How can I run symfony 2 run command from controller
Just to get you started, this should work in concept. I didn't get to run it, so I assume it might need a little tweaks from your side.
<?php
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand;
// your controller
public function myAction()
{
$command = new CreateSchemaDoctrineCommand();
$command->setContainer($this->container);
$input = new ArrayInput(array('--dump-sql' => true));
$output = new NullOutput();
$schema = $command->run($input, $output); //This is your schema
// Write it to a file if you want
file_put_contents('path/to/schema.sql', $schema);
}
References:
Similar question
PHP file_put_contents()
Symfony2 FileSystem
I try to create a Progress bar wait for server do something. When server finish then processbar will completed.
Here is my js
var pbar4 = Ext.create('Ext.ProgressBar', {
text:'Waiting on you...',
width: 300,
renderTo:Ext.getBody()
});
Ext.Ajax.request({
url: 'getStatus.php',
success: function(r) {
if (r.responseText == 100)
pbar4.updateText('All finished!');
else
pbar4.updateProgress(r.responseText, r.responseText+'% completed...');
}
});
and getStatus.php
$total = 10000;
for ($i = 0; $i <= $total; $i++) {
echo $i/$total*100;
}
But when i run that look like
How to do that thanks
What you have here is confusion about how ajax reacts with the page on the server. More specifically that pages aren't as stateful as you imagine them to be.
What you are assuming (or wanting) to happen:
Ajax request is made to PHP page from web page
PHP page receieves ajax request
PHP page starts loop
PHP page starts printing numbers
PHP page returns the current number it's on to the web page doing the ajax request
web page updates progress bar with first value
web page requests with ajax again
PHP prints out the current number it's on and returns that value to the requesting page
web page updates progress bar with current value
rinse and repeat steps 7 through 9
What is actually happening is quite simple:
Ajax request is made to PHP page from web page
PHP page receieves ajax request
PHP page starts loop
PHP prints all numbers in loop
PHP returns list of all numbers to web page
Web page prints list of all numbers as an update to the progress listener
To fix this issue you actually need to have the PHP page somehow be stateful as to the progress you want to represent here. This can be done by having PHP start a process (new thread, not sure if php has this) that writes numbers to a file on the first request and then have subsequence requests from the webpage read the last number in the file and have it return it. You could also use a database to do something similar.
In case somebody's looking now, I am also thinking of using a progressbar to monitor my Ajax. As previously mentioned, you cannot loop-print in PHP and read that. I did it like this:
Create a monitor ID in ExtJS.
Do the Ext.Ajax, passing the monitor ID
Create a Ext.util.TaskRunner();, monitoring a server file containing Jand updating progress bar
PHP side creates JSON file from monitor ID passed by ExtJS.
Update the JSON file in PHP by calling this several times:
Code:
$cnt = 0;
$total = 17; //number of times sendStatus(); was called
$monitorPath = '/path/to/file' . $_REQUEST['fileNameFromExtJS']
function sendStatus()
{
global $cnt, $total, $monitorPath;
$statusMessage = array(
"Tinkering stuff..",
"50% complete..",
"Sending...",
"Done!");
$statusMessage = $statusMessage[$cnt];
$cnt ++;
$str = '{"count": '.$cnt.', "total": '.$total.', statusMessage: "'.$statusMessage.'"}';
file_put_contents($monitorPath, $str, LOCK_EX );
}
Reference:
How to update Extjs Progress Bar with JSON results?
Progress bar in your web application, ExtJS / JAVA
What is the best way to spit out XML for webservice in CakePHP?
I have it like the following but it's displaying an empty page.
Sample call /service/config.xml
In Controller
var $helpers = array('Xml');
function config() {
$this->autoRender = false;
$obj = array("response" => array("config" => array(...)));
$objXmlHelper = new XmlHelper();
$objXml = $objXmlHelper->header();
$objXml .= $objXmlHelper->serilize($obj);
echo $objXml;
}
That gives empty page. However, if I echo json_encode($obj); that actually prints out json.
Thanks,
Tee
You probably have an error in your code. My guess is you are not including the XML helper.
Check you CakePHP (app/tmp/logs/) and PHP logs. In addition you may need to set the DEBUG flag to a higher level ( i.e. > 0).
I'd also recommend considering moving such things to a model. Web Services are typically data access layers and that belongs in the Model.