Retrieve data from database on the home page [closed] - mysql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am beginner in programming with the CakePhp framework and I want to dispaly data from the database on the HOME page of the website.
I've already create the model + view + controller.
Thank you.

You can either do that in your homepage controller
<?php
class HompageController extends AppController {
public function index(){
...
//For us to be able to call a different Model if it doesnt have a relationship with this model. Instantiate Product Model
$Products = ClassRegistry::init('Product');
//to get the data in product database. you can do it in two ways
//1. use the find method to get all data in Product database
$myproducts = $Products->find('all');
//2. or call some function in your Product model e.g. get_products() that return the data.
$myproducts = $Products->get_products();
//pass myproducts variable to homepage index
$this->set('myproducts', $myproducts);
}
?>

Related

ES6 How to process string interpolation if the function is returned after the string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
I have a function that returns an interpolated string for example.
`This is my string $t(some.value)`
The issue I am facing is that t is returned after I get the interpolated string. For example
const mainFunction = (targetString) => {
const { t } = getTranslationService();
return targetString;
}
I want to resolve the value and return the processed string in the mainFunction. I tried with eval but it didn't work
The answer in case it is useful for someone else
My first assumption was wrong, the function t is async.
The second was it was more complex than I expected, I needed to create a locale folder with a file en-US.json since how it works and all these it is relying on i18n
Finally, the target string should be in the JSON file. the t function will call a key from the JSON file and the targetString (enclosed between curly braces) will be translated. All this works in an asynchronic way.
you can do:
`This is my string ${t(some.value)}`
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

how generate a document with repeated objects [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
guys I have this code which is written in Json as it is supposed to generate a document with repeated objects _id and items
I have used repeat function and passed a list to it with these objects , also i do not have clear understanding about what objectid do
'repeat(21, 0)': [ {_id :objectId()}
, items : items()} ]
but it is giving me this error SyntaxError: Unexpected token :
I am using this site https://next.json-generator.com
solved guys , you can find the code below
[
{
'repeat(21, 0)': {
_id: '{{objectId()}}',
items: '{{company().toUpperCase()}}',
}
}
]
it is a list with an object which contain a function repeating its containing objects
, please correct me if i am wrong or give more clarification.

how to get the second element of json [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
I have this JSON
[
["pimenta & guedes", "Rodrigo"],
["24", "29"],
["32", "10"],
["77", "5"],
["Cartao", ""]
]
How can I get the second element, Rodrigo?
I am using Robot Framework and I have tried this command :
${FILECONTENT}= Get File c:/aa/webdemo-master2/login_tests/sample.txt
#Log to console ${FILECONTENT}
${JSON}= evaluate json.loads($FILECONTENT) json
Log to console ${JSON}
Log Hello, my name is ${JSON[0]}
But the result is (Hello, my name is ['pimenta & guedes', 'Rodrigo'])
But I would like to get (Hello, my name is Rodrigo)
Thanks in advance.
Your JSON is a two dimensional array. ${JSON[0][1]} should give you what you are looking for.

Angular 7 correct way to check if JSON parse returns a specific object [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm a little confused about this.
I have a server returning a JSON string that represents an array of custom objects that I have defined. I need to perform some tests and check if each element of this array can be correctly cast/parsed to my object.
What is the correct way to do this?
I thought about creating a new Object and passing my JSON.parse(element) result to the constructor, but then how do I check if it was correctly created? Does it throw an exception?
Here is the simple way to check it:
checkJsonObject(string) {
try {
JSON.parse(string);
} catch (e) {
return false;
}
return true;
}

Remove element from JSON object by value [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have the next JSON object
console.log:
Object {0: "/files/f6/bd/05/a9/medium/f6bd05a970c63b77eae164a607441818.jpeg",
1: "/files/ff/54/e3/17/medium/ff54e317d47631661eafeec6638ec530.jpeg",
2: "/files/b3/27/63/17/medium/b3276317020322ef77ac39447075286e.jpeg"}
And I need to remove element from this object by this string:
/files/f6/bd/05/a9/medium/f6bd05a970c63b77eae164a607441818.jpeg
I read a plenty of solutions for this question but all of them was about object with not numeric indexes. I use jQuery for it.
Please help me with function for my trouble. Thanks in advance.
Iterate through the object to find the value and delete the key once found:
// Assuming your object is called "foo":
for ( var k in foo ) {
if (foo.hasOwnProperty(k)) {
if (foo[k] === '/files/f6/bd/05/a9/medium/f6bd05a970c63b77eae164a607441818.jpeg') {
delete foo[k];
}
}
}
console.log(foo);