Extracting Cakephp Multidimensional arrays











up vote
0
down vote

favorite












I need to find all the records from an array of id ( $user_id = array(); ) to be saved into a table of notifications, to tell these users that their accounts are activated.



After executed these,



$x = $this->User->find('all',array('conditions'=>array('User.id'=>$user_id)));
$find = Set::extract('/User', $x);


I get this result:



Array( 
[0] => Array
(
[User] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

)
[1] => Array
(
[User] => Array
(
[id] => 3
[name] => lambert
[age] => 14
[class] => E
)

)
)


I need to achive the array below by extracting the one above



Array
{
[id] => 2
[name] => joe
[age] => 13
[class] => D
}
Array
{
[id] => 3
[name] => lambert
[age] => 14
[class] => E
}


How to make this happen using CakePHP?
Then, inside my view, how to send multiple records based on the extracted array above?
Is it possible to make a foreach loop inside view?



 echo $html->link(__('Send',true),array('controller'=>'users','action'=>'notifications',$user_id),array('class'=>'button'));


Obviously, putting the link inside the loop will result in two links with different ids ($user_id = 2 and $user_id = 3). I don't want that to happen. I want a single link that will submit these ids in one go.










share|improve this question
























  • 1) Yes you could loop in view. 2) Doesn't a form make more sense, then you could use a button to POST all the ids. Although, extracting all the ids like {n}.User.id and passing that to link() method should work. Creating a url that looks like controller/action/id=1&id=2 afaik. Still a POST makes more sense.
    – tigrang
    May 12 '12 at 17:13












  • To be more clear about the latter part of my comment, 'id' => $arrOfExtractedIds in the link array (2nd param of link() method. Or $ids = array('id' => $arrOfExtractedIds'); and '?' => $ids to pass as GET params
    – tigrang
    May 12 '12 at 17:22












  • In the view, I didn't create forms. Form is created inside the controller (including saveAll). I do $this->set('users_details',$users_details) to display all the users information inside the .ctp file.(Just for display - name,class etc.). The Submit button is the only thing that will run the submission. Can this be achived without $this->User->create inside the view? Simply said, the users info is already saved inside the controller, I just need to notify them that their accounts are ready by clicking the Submit button that will send out the information to them.
    – foxns7
    May 12 '12 at 22:23












  • I suggest you use bin.cakephp.org and paste your controller, model, and form as I can't understand what you are trying to do.
    – tigrang
    May 12 '12 at 22:54















up vote
0
down vote

favorite












I need to find all the records from an array of id ( $user_id = array(); ) to be saved into a table of notifications, to tell these users that their accounts are activated.



After executed these,



$x = $this->User->find('all',array('conditions'=>array('User.id'=>$user_id)));
$find = Set::extract('/User', $x);


I get this result:



Array( 
[0] => Array
(
[User] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

)
[1] => Array
(
[User] => Array
(
[id] => 3
[name] => lambert
[age] => 14
[class] => E
)

)
)


I need to achive the array below by extracting the one above



Array
{
[id] => 2
[name] => joe
[age] => 13
[class] => D
}
Array
{
[id] => 3
[name] => lambert
[age] => 14
[class] => E
}


How to make this happen using CakePHP?
Then, inside my view, how to send multiple records based on the extracted array above?
Is it possible to make a foreach loop inside view?



 echo $html->link(__('Send',true),array('controller'=>'users','action'=>'notifications',$user_id),array('class'=>'button'));


Obviously, putting the link inside the loop will result in two links with different ids ($user_id = 2 and $user_id = 3). I don't want that to happen. I want a single link that will submit these ids in one go.










share|improve this question
























  • 1) Yes you could loop in view. 2) Doesn't a form make more sense, then you could use a button to POST all the ids. Although, extracting all the ids like {n}.User.id and passing that to link() method should work. Creating a url that looks like controller/action/id=1&id=2 afaik. Still a POST makes more sense.
    – tigrang
    May 12 '12 at 17:13












  • To be more clear about the latter part of my comment, 'id' => $arrOfExtractedIds in the link array (2nd param of link() method. Or $ids = array('id' => $arrOfExtractedIds'); and '?' => $ids to pass as GET params
    – tigrang
    May 12 '12 at 17:22












  • In the view, I didn't create forms. Form is created inside the controller (including saveAll). I do $this->set('users_details',$users_details) to display all the users information inside the .ctp file.(Just for display - name,class etc.). The Submit button is the only thing that will run the submission. Can this be achived without $this->User->create inside the view? Simply said, the users info is already saved inside the controller, I just need to notify them that their accounts are ready by clicking the Submit button that will send out the information to them.
    – foxns7
    May 12 '12 at 22:23












  • I suggest you use bin.cakephp.org and paste your controller, model, and form as I can't understand what you are trying to do.
    – tigrang
    May 12 '12 at 22:54













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need to find all the records from an array of id ( $user_id = array(); ) to be saved into a table of notifications, to tell these users that their accounts are activated.



After executed these,



$x = $this->User->find('all',array('conditions'=>array('User.id'=>$user_id)));
$find = Set::extract('/User', $x);


I get this result:



Array( 
[0] => Array
(
[User] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

)
[1] => Array
(
[User] => Array
(
[id] => 3
[name] => lambert
[age] => 14
[class] => E
)

)
)


I need to achive the array below by extracting the one above



Array
{
[id] => 2
[name] => joe
[age] => 13
[class] => D
}
Array
{
[id] => 3
[name] => lambert
[age] => 14
[class] => E
}


How to make this happen using CakePHP?
Then, inside my view, how to send multiple records based on the extracted array above?
Is it possible to make a foreach loop inside view?



 echo $html->link(__('Send',true),array('controller'=>'users','action'=>'notifications',$user_id),array('class'=>'button'));


Obviously, putting the link inside the loop will result in two links with different ids ($user_id = 2 and $user_id = 3). I don't want that to happen. I want a single link that will submit these ids in one go.










share|improve this question















I need to find all the records from an array of id ( $user_id = array(); ) to be saved into a table of notifications, to tell these users that their accounts are activated.



After executed these,



$x = $this->User->find('all',array('conditions'=>array('User.id'=>$user_id)));
$find = Set::extract('/User', $x);


I get this result:



Array( 
[0] => Array
(
[User] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

)
[1] => Array
(
[User] => Array
(
[id] => 3
[name] => lambert
[age] => 14
[class] => E
)

)
)


I need to achive the array below by extracting the one above



Array
{
[id] => 2
[name] => joe
[age] => 13
[class] => D
}
Array
{
[id] => 3
[name] => lambert
[age] => 14
[class] => E
}


How to make this happen using CakePHP?
Then, inside my view, how to send multiple records based on the extracted array above?
Is it possible to make a foreach loop inside view?



 echo $html->link(__('Send',true),array('controller'=>'users','action'=>'notifications',$user_id),array('class'=>'button'));


Obviously, putting the link inside the loop will result in two links with different ids ($user_id = 2 and $user_id = 3). I don't want that to happen. I want a single link that will submit these ids in one go.







cakephp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 2:23









Cœur

17.2k9102141




17.2k9102141










asked May 12 '12 at 13:59









foxns7

3832617




3832617












  • 1) Yes you could loop in view. 2) Doesn't a form make more sense, then you could use a button to POST all the ids. Although, extracting all the ids like {n}.User.id and passing that to link() method should work. Creating a url that looks like controller/action/id=1&id=2 afaik. Still a POST makes more sense.
    – tigrang
    May 12 '12 at 17:13












  • To be more clear about the latter part of my comment, 'id' => $arrOfExtractedIds in the link array (2nd param of link() method. Or $ids = array('id' => $arrOfExtractedIds'); and '?' => $ids to pass as GET params
    – tigrang
    May 12 '12 at 17:22












  • In the view, I didn't create forms. Form is created inside the controller (including saveAll). I do $this->set('users_details',$users_details) to display all the users information inside the .ctp file.(Just for display - name,class etc.). The Submit button is the only thing that will run the submission. Can this be achived without $this->User->create inside the view? Simply said, the users info is already saved inside the controller, I just need to notify them that their accounts are ready by clicking the Submit button that will send out the information to them.
    – foxns7
    May 12 '12 at 22:23












  • I suggest you use bin.cakephp.org and paste your controller, model, and form as I can't understand what you are trying to do.
    – tigrang
    May 12 '12 at 22:54


















  • 1) Yes you could loop in view. 2) Doesn't a form make more sense, then you could use a button to POST all the ids. Although, extracting all the ids like {n}.User.id and passing that to link() method should work. Creating a url that looks like controller/action/id=1&id=2 afaik. Still a POST makes more sense.
    – tigrang
    May 12 '12 at 17:13












  • To be more clear about the latter part of my comment, 'id' => $arrOfExtractedIds in the link array (2nd param of link() method. Or $ids = array('id' => $arrOfExtractedIds'); and '?' => $ids to pass as GET params
    – tigrang
    May 12 '12 at 17:22












  • In the view, I didn't create forms. Form is created inside the controller (including saveAll). I do $this->set('users_details',$users_details) to display all the users information inside the .ctp file.(Just for display - name,class etc.). The Submit button is the only thing that will run the submission. Can this be achived without $this->User->create inside the view? Simply said, the users info is already saved inside the controller, I just need to notify them that their accounts are ready by clicking the Submit button that will send out the information to them.
    – foxns7
    May 12 '12 at 22:23












  • I suggest you use bin.cakephp.org and paste your controller, model, and form as I can't understand what you are trying to do.
    – tigrang
    May 12 '12 at 22:54
















1) Yes you could loop in view. 2) Doesn't a form make more sense, then you could use a button to POST all the ids. Although, extracting all the ids like {n}.User.id and passing that to link() method should work. Creating a url that looks like controller/action/id=1&id=2 afaik. Still a POST makes more sense.
– tigrang
May 12 '12 at 17:13






1) Yes you could loop in view. 2) Doesn't a form make more sense, then you could use a button to POST all the ids. Although, extracting all the ids like {n}.User.id and passing that to link() method should work. Creating a url that looks like controller/action/id=1&id=2 afaik. Still a POST makes more sense.
– tigrang
May 12 '12 at 17:13














To be more clear about the latter part of my comment, 'id' => $arrOfExtractedIds in the link array (2nd param of link() method. Or $ids = array('id' => $arrOfExtractedIds'); and '?' => $ids to pass as GET params
– tigrang
May 12 '12 at 17:22






To be more clear about the latter part of my comment, 'id' => $arrOfExtractedIds in the link array (2nd param of link() method. Or $ids = array('id' => $arrOfExtractedIds'); and '?' => $ids to pass as GET params
– tigrang
May 12 '12 at 17:22














In the view, I didn't create forms. Form is created inside the controller (including saveAll). I do $this->set('users_details',$users_details) to display all the users information inside the .ctp file.(Just for display - name,class etc.). The Submit button is the only thing that will run the submission. Can this be achived without $this->User->create inside the view? Simply said, the users info is already saved inside the controller, I just need to notify them that their accounts are ready by clicking the Submit button that will send out the information to them.
– foxns7
May 12 '12 at 22:23






In the view, I didn't create forms. Form is created inside the controller (including saveAll). I do $this->set('users_details',$users_details) to display all the users information inside the .ctp file.(Just for display - name,class etc.). The Submit button is the only thing that will run the submission. Can this be achived without $this->User->create inside the view? Simply said, the users info is already saved inside the controller, I just need to notify them that their accounts are ready by clicking the Submit button that will send out the information to them.
– foxns7
May 12 '12 at 22:23














I suggest you use bin.cakephp.org and paste your controller, model, and form as I can't understand what you are trying to do.
– tigrang
May 12 '12 at 22:54




I suggest you use bin.cakephp.org and paste your controller, model, and form as I can't understand what you are trying to do.
– tigrang
May 12 '12 at 22:54












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The answer for your first question



 $data_final =array();
foreach($findas $d)
{
$data_final =$d['User'];
}


then you wil achive



Array
(
[0] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

[1] => Array
(
[id] => 4
[name] => lamber
[age] => 23
[class] => E
)

)


The answer to second question
the way you are doing with url is not a good practice. you should post the records






share|improve this answer























  • There are two typos in the foreach loop.
    – tigrang
    May 12 '12 at 17:28










  • what do u mean by two typos ?
    – Moyed Ansari
    May 12 '12 at 17:30










  • foreach($$findas $d) Should be foreach($find as $d)
    – tigrang
    May 12 '12 at 17:38










  • thanks for helping :)
    – Moyed Ansari
    May 12 '12 at 17:39











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10564387%2fextracting-cakephp-multidimensional-arrays%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










The answer for your first question



 $data_final =array();
foreach($findas $d)
{
$data_final =$d['User'];
}


then you wil achive



Array
(
[0] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

[1] => Array
(
[id] => 4
[name] => lamber
[age] => 23
[class] => E
)

)


The answer to second question
the way you are doing with url is not a good practice. you should post the records






share|improve this answer























  • There are two typos in the foreach loop.
    – tigrang
    May 12 '12 at 17:28










  • what do u mean by two typos ?
    – Moyed Ansari
    May 12 '12 at 17:30










  • foreach($$findas $d) Should be foreach($find as $d)
    – tigrang
    May 12 '12 at 17:38










  • thanks for helping :)
    – Moyed Ansari
    May 12 '12 at 17:39















up vote
1
down vote



accepted










The answer for your first question



 $data_final =array();
foreach($findas $d)
{
$data_final =$d['User'];
}


then you wil achive



Array
(
[0] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

[1] => Array
(
[id] => 4
[name] => lamber
[age] => 23
[class] => E
)

)


The answer to second question
the way you are doing with url is not a good practice. you should post the records






share|improve this answer























  • There are two typos in the foreach loop.
    – tigrang
    May 12 '12 at 17:28










  • what do u mean by two typos ?
    – Moyed Ansari
    May 12 '12 at 17:30










  • foreach($$findas $d) Should be foreach($find as $d)
    – tigrang
    May 12 '12 at 17:38










  • thanks for helping :)
    – Moyed Ansari
    May 12 '12 at 17:39













up vote
1
down vote



accepted







up vote
1
down vote



accepted






The answer for your first question



 $data_final =array();
foreach($findas $d)
{
$data_final =$d['User'];
}


then you wil achive



Array
(
[0] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

[1] => Array
(
[id] => 4
[name] => lamber
[age] => 23
[class] => E
)

)


The answer to second question
the way you are doing with url is not a good practice. you should post the records






share|improve this answer














The answer for your first question



 $data_final =array();
foreach($findas $d)
{
$data_final =$d['User'];
}


then you wil achive



Array
(
[0] => Array
(
[id] => 2
[name] => joe
[age] => 13
[class] => D
)

[1] => Array
(
[id] => 4
[name] => lamber
[age] => 23
[class] => E
)

)


The answer to second question
the way you are doing with url is not a good practice. you should post the records







share|improve this answer














share|improve this answer



share|improve this answer








edited May 12 '12 at 17:39

























answered May 12 '12 at 17:23









Moyed Ansari

7,50222548




7,50222548












  • There are two typos in the foreach loop.
    – tigrang
    May 12 '12 at 17:28










  • what do u mean by two typos ?
    – Moyed Ansari
    May 12 '12 at 17:30










  • foreach($$findas $d) Should be foreach($find as $d)
    – tigrang
    May 12 '12 at 17:38










  • thanks for helping :)
    – Moyed Ansari
    May 12 '12 at 17:39


















  • There are two typos in the foreach loop.
    – tigrang
    May 12 '12 at 17:28










  • what do u mean by two typos ?
    – Moyed Ansari
    May 12 '12 at 17:30










  • foreach($$findas $d) Should be foreach($find as $d)
    – tigrang
    May 12 '12 at 17:38










  • thanks for helping :)
    – Moyed Ansari
    May 12 '12 at 17:39
















There are two typos in the foreach loop.
– tigrang
May 12 '12 at 17:28




There are two typos in the foreach loop.
– tigrang
May 12 '12 at 17:28












what do u mean by two typos ?
– Moyed Ansari
May 12 '12 at 17:30




what do u mean by two typos ?
– Moyed Ansari
May 12 '12 at 17:30












foreach($$findas $d) Should be foreach($find as $d)
– tigrang
May 12 '12 at 17:38




foreach($$findas $d) Should be foreach($find as $d)
– tigrang
May 12 '12 at 17:38












thanks for helping :)
– Moyed Ansari
May 12 '12 at 17:39




thanks for helping :)
– Moyed Ansari
May 12 '12 at 17:39


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10564387%2fextracting-cakephp-multidimensional-arrays%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'