I am new to CakePHP 2.0. It has too many changes from its previous version. I have many problems with implementing basic functionality in CakePHP 2.0. I did the same code in CakePHP 1.3 and 2.0 but the output is different so it creates a problem for me.
I have created one form as shown below:
<form name="User" method="post" action="http://192.168.1.24/project/api/documents/sub" ENCTYPE="multipart/form-data">
<table>
<tr><td><label>username:</label></td><td><input type="text" name="username"></td></tr>
<tr><td><label>password:</label></td><td><input type="text" name="password"></td></tr>
<tr><td><label>email:</label></td><td><input type="text" name="email"></td></tr>
<tr><td><label>Image:</label></td><td><input type="file" name="image"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit" />
I used this form for both my applications in CakePHP 1.3 and 2.0.
The controller code of CakePHP 1.3 is:
function api_sub()
{
$this->layout = false;
$this->data['Document'] = $this->params['form'];
pr($this->data); die();
}
The output of the above code is:
Array
(
[Document] => Array
(
[username] => mack
[password] => meack
[email] => mack#gmail.com
[submit] => Submit
[image] => Array
(
[name] => 01manta.jpg
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\phpF586.tmp
[error] => 0
[size] => 636306
)
)
)
The controller code in CakePHP 2.0 is as shown below:
public function api_sub()
{
//$this->layout = false;
$this->request->data['Document']= $this->request->data;
pr($this->request->data); die();
}
The output of the above code is as shown below:
Array
(
[username] => mack
[password] => meack
[email] => mack#gmail.com
[submit] => Submit
[User] => Array
(
[username] => mack
[password] => meack
[email] => mack#gmail.com
[submit] => Submit
)
)
Now the problem is that in CakePHP 2.0, the image array is missing in the output.
Can anyone tell me how I can get that image array in CakePHP 2.0? What changes do I have to do in my coding?
I could be because you're not using the FormHelper. Were you to use said helper the data would probably be properly populated in $this->data or $this->request->data. I can't find anything definitive on the matter the documentation though.
In any case, generic form data is always present in $this->request->params['form'], so the file data for your form would be in $this->request->params['form']['file'].
Instead of writing the HTML code for the form, you should do as follow:
echo $this->Form->create('ModelName');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('email');
echo $this->Form->input('image');
echo $this->Form->end('Submit!');
Note that in this example asumes you'll validate the image wihtin your model and it will probably be stored in your database.
Shoud you wish not to store the image in the database, you could replace the last input with:
echo $this->Form->input('image', array('type' => 'file'));
All of this will be accessible in your Controller through:
$this->request->data
This will be an array that should look like this:
array(
'ModelName' => array(
'username' => 'whatever_the_user_wrote',
'password'=> '********',
'email' => 'foo#bar.baz',
'image' => the image
)
)
Link to the Book: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
Link to the API: http://api.cakephp.org/class/form-helper
Related
I'm trying to import a CSV File with Codeigniter, which contains the code below:
Voornaam;Achternaam;email
John;Doe;john.doe#gmail.com
Man;Made;man#made.com
The file is successfully uploaded, and when I print the code through PHP it indeed shows me the file contents in an array:
Array ( [0] => Array ( [Voornaam] => John [Achternaam] => Doe [email] => john.doe#gmail.com ) [1] => Array ( [Voornaam] => Man [Achternaam] => Made [email] => man#made.com ) )
The code is then processed through the following code:
foreach($csv_array as $row) {
$insertData = array(
'firstName' => $row['Voornaam'],
'lastName' => $row['Achternaam'],
'email' => $row['email']
);
};
Which unfortunately 'Undefined index: Voornaam' When i replace $row['Voornaam'] with '', the code processes fine, so lastName and email work. Now, I cannot for the life of me figure out why Voornaam is not processed, and how it may be fixed.
Can someone explain to me how I can trigger Celery tasks through Logstash?
Is it possible?
If I try to do that in PHP through the 'php-amqplib' library it works fine: (without using Logstash)
$connection = new AMQPStreamConnection(
'rabbitmq.local',
5672,
'guest',
'guest'
);
$channel = $connection->channel();
$channel->queue_declare(
'celery',
false,
true,
false,
false
);
$taskId = rand(1000, 10000);
$props = array(
'content_type' => 'application/json',
'content_encoding' => 'utf-8',
);
$body = array(
'task' => 'process_next_task',
'lang' => 'py',
'args' => array('ktest' => 'vtest'),
'kwargs' => array('ktest' => 'vtest'),
'origin' => '#'.'mytest',
'id' => $taskId,
);
$msg = new AMQPMessage(json_encode($body), $props);
$channel->basic_publish($msg, 'celery', 'celery');
According to the Celery docs:
http://docs.celeryproject.org/en/latest/internals/protocol.html
I'm trying to send the request in the json format, this is my Logstash filter:
ruby
{
remove_field => ['headers', '#timestamp', '#version', 'host', 'type']
code => "
event.set('properties',
{
:content_type => 'application/json',
:content_encoding => 'utf-8'
})
"
}
And Celery answer is:
[2017-05-05 14:35:09,090: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!
{content_type:None content_encoding:None delivery_info:{'exchange': 'celery', 'routing_key': 'celery', 'redelivered': False, 'consumer_tag': 'None4', 'delivery_tag': 66} headers={}}
Basically, Celery is not able to decode my message format or better... I'm not able to set the request in the JSON format :)
It's driving me crazy, thank you in advance for any clues :)
Forgot it, this is my output plugin in Logstash
rabbitmq
{
key => "celery"
exchange => "celery"
exchange_type => "direct"
user => "${RABBITMQ_USER}"
password => "${RABBITMQ_PASSWORD}"
host => "${RABBITMQ_HOST}"
port => "${RABBITMQ_PORT}"
durable => true
persistent => true
codec => json
}
From the information provided in this question, you can't.
When you're playing with the event in the ruby filter, you're actually playing with what will be put in the body of the message, while you'd like to set the rabbitmq headers and properties of your message.
Till that functionality has been tackled, I do not think you'll be able to achieve it unless of course you implement it yourself. After all, the plugin is available on github.
As Olivier said, right now is not possible but I've created a pull request to the official project.
https://github.com/logstash-plugins/logstash-output-rabbitmq/pull/59
If you are looking for a working version take a look to my clone:
https://github.com/useless-stuff/logstash-output-rabbitmq
You should be seriously scared about that code :)
I'm completely far away to be a Ruby developer
But it works :)
FACTS:
I am not very good at magento but have some experience working with API's using PHP.
TARGET:
What I actually want to do is
Download magento customer orders in our order system
Process the orders
Upload tracking code back to magento
Update magento products level based on the values fetched from our local Stock System running on a different server
ENVIRONMENT:
I am using a Login Plugin to make the store private so only customers with an account can access it.
PROBLEM:
IF 'AUTHENTICATION' PLUGIN IS DISABLED EVERYTHING WORKS FINE. BUT WHEN PLUGIN IS ENABLED STEP 3 AND 4 STOP WORKING.
ERROR SAMPLE:
Magento SOAP API V2 calls result in
SoapFault Object ( [message:protected] => looks like we got no XML document, when used for Private Sales store. I am able to login using API a/c,fetch orders but calls to update stock / upload tracking etc fail.
SAMPLE OUTPUT:
Login Successful [0a254c064fa033859bc75db94]
Request :
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento"><SOAP-ENV:Body><ns1:catalogInventoryStockItemUpdateRequestParam>sessionId>0a254c064fa033859bc75db94</sessionId><productId>1</productId><data><qty>100</qty><is_in_stock>1</is_in_stock></data></ns1:catalogInventoryStockItemUpdateRequestParam></SOAP-ENV:Body></SOAP-ENV:Envelope>
Result:
SoapFault Object ( [message:protected] => looks like we got no XML document [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/vhosts/XXX/magentoAPI/stock.php [line:protected] => 31 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/vhosts/XXX/magentoAPI/stock.php [line] => 31 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => catalogInventoryStockItemUpdate [1] => Array ( [0] => stdClass Object ( [sessionId] => 0a254c064fa033859bc75db94 [productId] => 1587 [data] => Array ( [qty] => 1000 [is_in_stock] => 1 ) ) ) ) ) [1] => Array ( [file] => /var/www/vhosts/XXX/magentoAPI/stock.php [line] => 31 [function] => catalogInventoryStockItemUpdate [class] => SoapClient [type] => -> [args] => Array ( [0] => stdClass Object ( [sessionId] => 0a254c064fa033859bc75db94 [productId] => 1587 [data] => Array ( [qty] => 1000 [is_in_stock] => 1 ) ) ) ) ) [previous:Exception:private] => [faultstring] => looks like we got no XML document [faultcode] => Client [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ )
Hello Stack Overflow Community
I am having some problems with my custom paths in my zend framework 2 module.
I've added following code to my module.config.php :
// custom configuration
'custom' => array(
'paths' => array(
'pickUpDir' => '/var/www/beam/public/in/',
'errorDir' => '/var/www/beam/public/error/',
'temporaryDir' => '/var/www/beam/module/Beam/temp/',
'archiveDir' => '/var/www/beam/module/Beam/archive/'
)
),
Now this works fine on my virtual developement server but i want it to work universaly, meaning if i put my Zend Framework application on a live server which has a different folder structure it should still work.
Is there a way to declare relative paths or something like that ?
Many thankx in advance
The magic constant __DIR__ will return the current directory which should be /..../Yourmodel/config/.
From there on you could just do:
'custom' => array(
'paths' => array(
'pickUpDir' => __DIR__ . '/../../public/in/',
'errorDir' => __DIR__ . '/../../public/error/',
//etc
)
),
Alternatively to cptnk's answer (which is also working), you can also use the get_cwd() function that will return you the root of your webapp, so that you can write stg like
'custom' => array(
'paths' => array(
'pickUpDir' => get_cwd() . '/public/in/',
'errorDir' => get_cwd() . '/public/error/',
//etc
)
)
as ZF2 defines the current working directory as root of your project.
I have a little problem.
There are two tables in my database: users and classes. The first one contains info about users, and the second one - about user classes and about access rights.
Now I'm extracting all data from there using this:
SELECT * FROM users NATURAL JOIN classes WHERE users.ID_User = '$id';
The mysql code works and returns a right array.
Now, when I'm doing next:
<?php
$result = mysql_query($sql_above);
$row = mysql_fetch_array($result);
print_r($row);
?>
... i'm getting this:
Array ( [0] => 1 [ID_User] => 1 [1] => John [Name] => John [2] => Doe [Surname] => Doe [3] => ... [16] => Owner [Class] => Owner [17] => [All] => [18] => [CanAuth] => [19] => [CanViewData] => [20] => [CanAddData] => [21] => [CanAlterData] => [22] => [CanDeactivateData] => [23] => [CanDeleteData] => [24] => [CanMgLocatari] => ... )
Columns from 17 till the end are access rights, noted in the database by 1 or 0. And there, they're missing.
Is there any option to enable in PHP configuration to correct this thing? Because on a Windows machine, the code executes properly and rights are working.
PHP Version 5.3.6-13ubuntu3.7 | Apache/2.2.20 (Ubuntu) | MySQL client version: 5.1.62
Please, reply. Thanks!