I've got a Cake application with a reports query interface, where the admin user can filter the data by various inputs in a form and the results are then displayed on the screen. I am looking for the simplest way to add a button which allows the user to download the results of this same query as CSV.
I'm sure I can create one for myself if I have to, but is there already a way to regenerate any given form based on $this->data? That way, I can just add .csv to the form action and use RequestHandler to choose the right output format.
[here take a look at the following...
instead of finding the data from Db you can simply pass $this->data to it.
take a look at follo
Exporting data to CSV the CakePHP way
I guess you have to replicate the function on your controller, one for generating the results on screen and another same function intended for csv, but on the function for csv it must have parameters which are similar to the values of $this->data. Use javascript to redirect on the function for csv.
Related
I am building a form with Cakephp 2.x and I want to submit some of the data that is received when submitting it to table A and the other data to table B. Does anyone know how to achieve this in cakephp?
I believe you need to look at Cakephp's model documentation. Looking at it now it seems that saveMany could help you with that. http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-savemany-array-data-null-array-options-array
Yes. You should do what you want follow below way:
1. Create method receiveData() in FooController.
2. Create view file receive_data.ctp in folder foo.
$this->Foo->create();
$this->Foo->input('....', array(....));
// other input.
$this->Foo->end();
3. In FooController\receiveData(), When submit, you have data array $myDataArray like this: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html#adding-posts
(Notice: It is Foo controller).
4. Before you save data from submitted data, you maybe need manipulation with submitted data array.
5.
You must call Model Bar inside FooController by:
$uses = array('Bar');
You will save to other table by:
$this->Bar->save($myDataArray);
(Notice: It is Bar Model).
Do Table A and Table B represent two different Models?
if yes saveAssociated might help you.
http://book.cakephp.org/2.0/en/models/saving-your-data.html#saving-related-model-data-hasone-hasmany-belongsto
If you want to save the same kind of model n times then saveMany is what you want to do.
My client requires a report that produces a comma separated list of files in one column of a grid. I know I can use a FOR XML Path in my query to yield these results. However, the client wants to be able to click on an individual value in that CSV and be taken to a link for that element in the list. For example, the column in the report would look like:
1.jpg, 2.jpg, 3.jpg
He needs the ability to click on the 2.jpg, and go to that actual file. I know I can put in an action for the entire field to go to one URL, but can I narrow that action down to a specific part of the CSV list?
You can use placeholders to embed hyperlinks in comma delimited text, you'll need to wrap each value with an anchor tag and href. See the URL Embedded in Text section of my earlier answer an example.
SQLFiddle of sample code for adding markup. It's ugly in SQL but works.
I came up with a workable solution. The problem seems to lie in the fact that there are multiple URLs in the list. If i only return a single URL, it works fine. so, instead of a CS list, I return one at a time and use a matrix to group the other fields.
I am new to pyrocms.
How can I get database values on pages of pyrocms. In website of pyrocms I had created a listing page now I want to display database values from pyro database table.
I got your question, you want to create a listing on your front-end page for some database table values which you want to access through your custom module controller. there are many ways to get these values but the simplest way is to use ajax. you already have Jquery added in pyrocms so you can simply make a call to your controller method in ajax and get your required output as HTML and display it in the div element on your page.
$.ajax({
type:"POST",
url:"admin/your-controller-name/your-method-name",
success:function(html){
$('yourdiv').html(html);
}
})
In your controller create a method which get data from database and print it using echo create some listing table etc what you want.
i think you will get my point. if confuse then get back to me
You need to be more specific as PyroCMS has lots of components and each module (blogs, variables, widgets, file uploads etc.) uses specific tags you insert into the page. You may come across references to 'Lex' - that's the name of the parser used to display them.
Tags documentation
PyroCMS (the Professional edition) also has a feature called "Streams" which allows you to build custom databases and this in turn has it's own series of tags.
I have a file that I wish to parse and add to the database.
The way I wish to do it is this:
The user uploads the file
File is parsed
The users are given the parsed data and selects what they want to keep
They submit
(More detailed explanation follows)
I have a film script file that I wish to parse and enter scenes and their respective characters and props. I have already managed to parse this file into an array using php.
What I want to do now is to
prompt the user with the various scenes and its contents
allow the user to fix / modify the data before submitting it into the database.
The thing is that the script file has more than one scene in it, so I am unsure how to handle the data-entry aspect of this problem.
Are there any "best practices" for these kinds of data entries?
(if I didn't explain something in enough detail, please tell me and I'll update the question).
I would simply parse the file and save it as it is to the database. Something like Script hasMany Scenes. Let them select their script and simply paginate the Scene records and let them delete them.
Is there an urgent need to not save them all after import? Another downside of your approach is that if the browser crashes or the user closes it he has to start over again because you just kept the data in memory but not persistant.
If you want to rely on your approach you'll have to work with the data coming back from the form and simply remove the key from the form data.
Like doing this in a foreach running over the data structure
if ($data['Scene][$key]['delete'] == 1) { unset($data['Scene'][$key]); }
for example i've got a form with some input fields(every form and it's inputs with validation rules are stored in database).
Every input got it's own OnChange() which posts json (i.e. new value, input element name, ...) to controller for validation, if validation passes the new value must be saved somewhere until user clicks submit button, which will save all data to database table.
And here i'd like to ask, what this special place between ui and database can be ?
p.s.
also if user closes browser/form the next time he'll come back i need to ask him if he would like to start from an empty form or fill form with values he previously entered there.
Thank You !
Cookies or intermediary database table would work for this case.
for an intermediary database like that, you could use something like MongoDB, it is really easy to get it started, you just work with the classes you have, don't need to setup any schema, you just save the objects
http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial
If you are submitting the entire form at the end, why can't you just store the values at that time? Is this a multi-page form(s)? Why not allow the database records to be partially filled? You could always add a bit column to mark the record as complete or incomplete. This would be much simpler than duplicating your table structure.