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.
cakephp
add a comment |
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.
cakephp
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 tolink()
method should work. Creating a url that looks likecontroller/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 oflink()
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
add a comment |
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.
cakephp
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
cakephp
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 tolink()
method should work. Creating a url that looks likecontroller/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 oflink()
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
add a comment |
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 tolink()
method should work. Creating a url that looks likecontroller/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 oflink()
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
add a comment |
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
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 beforeach($find as $d)
– tigrang
May 12 '12 at 17:38
thanks for helping :)
– Moyed Ansari
May 12 '12 at 17:39
add a comment |
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
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 beforeach($find as $d)
– tigrang
May 12 '12 at 17:38
thanks for helping :)
– Moyed Ansari
May 12 '12 at 17:39
add a comment |
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
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 beforeach($find as $d)
– tigrang
May 12 '12 at 17:38
thanks for helping :)
– Moyed Ansari
May 12 '12 at 17:39
add a comment |
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
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
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 beforeach($find as $d)
– tigrang
May 12 '12 at 17:38
thanks for helping :)
– Moyed Ansari
May 12 '12 at 17:39
add a comment |
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 beforeach($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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 tolink()
method should work. Creating a url that looks likecontroller/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 oflink()
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