Cakephp Populate HABTM Select Box In EDIT Form?

I am using cakephp's form for an HABTM relationship between User and Event. There is a join table events_users. The form works well for the Add form, but not for the edit form. The code is:

Controller:

$this->data = $this->Event->findById($id);

Form field:

$this->Form->input('User');

What I get is a blank, input box. Unlike the select box in the Add form. Any ideas what I'm doing wrong or how to populate a select box with the right Users selected for the input on the edit form?



ADVERTISEMENT

Drupal Get Parameters From Url In Edit Form And Populate The Form?

i have an employee table with fields like id, name, age and salary.

Iam showing the list of employee names in my custom module and when i click on an employee name, i have to show the edit form of that employee.

The employee names are given a link, as like:

<a href='".$base_url."/my_module/edit/".$employee->id."'>

and the corresponding menu path is configured as:

$items['my_module/edit/%'] = array(
'title' => t('My form'),
'description' => t('Edit employee'),
'page callback' => 'my_module_edit',
'access arguments' => array('access content'),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);

And when i click on the 5th employee name, the url would be: ..../my_module/edit/5

So now my questions are:

How can i get the id (5) of the employee from the url in my my_module_edit function ? How can i show the edit form of the employee, populating the fields (by querying with id) ?

View 3 Replies View Related

UpdateAll And HABTM In CakePHP

I have two models and a join table, User, Post and posts_users. The posts_users table contains a few extra fields, one of which is is_active. I want to set all of a users posts to active providing the user is active themselves. I have the following

$this->Post->PostsUser->updateAll(array('PostsUser.is_active' => 1), array('PostsUser.user_id' => $data['User']['id'], 'User.is_active' => 1));

Which causes a MySQL error

Warning (512): SQL Error: 1054: Unknown column 'User.is_active' in 'where clause' ... Query: UPDATE posts_sites AS PostsUser SET PostsUser.is_active = 1 WHERE PostsUser.user_id = 1 AND User.is_active = 1

As you can see the User table isn't getting joined in the query.

View 1 Replies View Related

HABTM Relationships In Cakephp Is Too Many?

I'm struggling with deciding how many HABTM relationships I really need in my cakephp app. I guess I don't quite get what "has" truly means. I don't want to have more HABTM tables than necessary. Here's what I have in my database:

Users
Properties
Leases
Payments
Repairs

user HABTM properties, user HABTM leases, user HABTM users, user HABTM repairs, property hasMany repairs, property hasMany leases, lease hasMany repairs.

Also, I have two aliases for my users model (manager and tenant). This is one of the reasons I ended up with so many HABTM relationships, but I'm not sure it's necessary.

Do I have too many user HABTM relationships? Would it be better to just have cake recurse through my models?

View 1 Replies View Related

Save Files With HABTM In CakePHP?

I am creating multiple associations in one go and there are a few problems when it comes to saving.I have the following code:

<?php
foreach($userData as $user) {
[code]............

View 2 Replies View Related

CakePHP Passing Id To Edit Form?

many different ways to pass an ID to a form when editing a database entry.So for example for a edit user profile form I have the following code:

function edit($id = null)
{
$this->layout = 'page';
// this line isn't needed?
//$this->User->id = $id;

[code]...

Now the function expects an id passing in the url e.g./users/edit/2 But let's say I wanted it to be something more user friendly like /profile/edit(rewrote by routing) I would no longer be passing in the ID as part of the url.As you can see in my code I have a line I have commented out because it isn't needed?Also in the form I ALSO Need <?php echo $this->Form->input('id', array('type' => 'hidden')); ?>why?Basically this is more of what are the options available to me to build various types of edit forms and passing data to the form.And what is the need for the hidden field in the form if the data is being passed either via the URL or some other way.

I've also noticed on some sites that they have things like Form Keys and the username stored in meta tags in the page header?
EDIT:
public function beforeFilter()
{
$this->set('authUser', $this->Auth->user());
//
$user = $this->Auth->user();

[code]...

View 1 Replies View Related

Cakephp 1.3 Paginating Habtm Related Data?

I have searched high and low and tried multiple different solutions to this and I cannot seem to get it to work. Basically I have products and categories. Categories has and belongs to many products, and products HABTM categories. They are obviously related in a join table products_categories with id,product_id,category_id fields.

After a simple full bake- models views and controllers are baked - some categories and products are added and their relationships are set I can go to a specific category view page and the pre baked view will show products that are related to this category.

However, there is quite a few products (and will be more) and I am struggling to work out how to paginate all of this related data..as it is unfeasible to just simply list all of the products in a category (there could be 100s or more) Can anybody help? It seems there are quite a few unanswered topics on this and various different solutions, none of which I can get to work!

View 1 Replies View Related

Making HABTM Relationships Unique In CakePHP?

I have two models, called Book and Tag, which are in a HABTM relationship. I want a couple (book, tag) to be saved only once. In my models I have

var $hasAndBelongsToMany = array(
'Tag' => array(
'className' => 'Tag',

[code]...

View 4 Replies View Related

CakePHP And HABTM Model Limit Error?

I've got a series of Post models that hasAndBelongsToMany Media models. In certain function calls inside of the Post model, I don't need to retrieve the entire list of Media models. However, when I use the following code:

$this->unbindModel( array('hasAndBelongsToMany' => array('Media')) );
// Rebind to get only the fields we need:
$this->bindModel(

[code]...

View 5 Replies View Related

Generate List With Habtm Relationship - CakePHP

I want to generate a list (dropdown) with habtm relationship, for example i have a table called "users" another called "vehicles" and "users_vehicles".

What i want is to get vehicles assigned to "x" user and put it in a dropdown, how i can achieve this?

class User extends AppModel {
var $hasAndBelongsToMany = array('Vehicle');
}

View 2 Replies View Related

Associating CakePHP HABTM Models Without A View?

I'm writing an import from CSV and have been able to successfully manually set data fields on a model in code by using the $this->Book->set() function and passing it a hash containing all of the fieldName => value pairings.

How do I create habtm associations in code? All the examples I've seen in the documentation are based on the $this->data returned from a form in the view. Because my data is coming from a csv file and not a view I can't use this!

So in the following example:

// Book habtm Tags
// Tag habtm Books
$this->Book->create();
$this->Book->set(

[Code]....

How would I associate the $arrayOfTagIds with the Book?

View 1 Replies View Related

CakePHP Find() Based On HABTM Relationships?

I'm working on a CakePHP 1.2 application. I have a model "User" defined with a few HABTM relationships with other tables through a join table. I'm now tasked with finding User information based on the data stored in one of these HABTM tables. Unfortunately, when the query executes, my condition is rejected with an error about a missing table. Upon inspection it seems that CakePHP is not including any of the HABTM tables in the select statement.

My User HABTM relationship is as follows:

var $hasAndBelongsToMany = array(
'Course' => array(
'className' => 'Course',
'joinTable' => 'course_members',
'foreignKey' => 'user_id',
'associationForeignKey' => 'course_id',

[Code]...

View 5 Replies View Related

CakePHP - HABTM - Sending Data From Multiple Tables To A View?

Scenario:
3 tables:
restaurants
cuisines
features

2 join tables:
cuisines_restaurants
features_restaurants

Question:
What is the best way to get data for a single restaurant from my controller to the view which includes not only the restaurant data, but also the cuisines and features that it has.

I have it working with this:

$restaurant = $this->Restaurant->find('all', array('conditions' =>
array('Restaurant.id' => $id)));
$this->set('restaurant', $restaurant);

And I'm calling it in the view like this:

echo "<span class='label'>Name:</span> " . $restaurant[0]['Restaurant']['name'] . "<br />";
echo "<span class='label'>Cuisine:</span> ";
$cuisineList = "";
foreach($restaurant[0]['Cuisine'] as $cuisine) {
$cuisineList .= $cuisine['name'] . ", ";
}
echo substr($cuisineList,0,-2) . "<br />";

(and repeat for Features)But this seems overkill, since in all the Cake tutorials I see, the view method in the controller just has:

$this->set('restaurant', $this->Restaurant->read(null, $id));

Then they call it like this:

echo $restaurant['Restaurant']['name'];
...etc
Again -it IS working-I just want to know if there's a better way-the way I'm currently doing it seems sloppy compared to all the other slick things Cake does for me!

View 1 Replies View Related

Save Additional Information To A CakePHP HABTM Join Table?

I'm unable to save a record to a HABTM join table manually. I have a table, users_products and would like to save all additional information about the order (size, quantity, color, etc...) to this join table, instead of creating a separate one. User $hasAndBelongsTo Product My users controller code to do so:

Configure::write('debug', 0);
//adds product to cart
$this->layout = ""; //async
$user = $this->User->find('first',array('conditions'=>array('User.id'=>$this->Auth->user("id"))));
$data['User'] = $user['User'];
$addition = array('user_id' => $this->Auth->user("id"),
'product_id' => $id,
[Code]...

Unfortunately, this adds a new record to the database and clears out the entire join table while doing so.

View 2 Replies View Related

Post To A Form And Populate A Select Multiple?

I'm doing something a bit strange here, I'm querying data out of my local database and posintg it to Salesforce form using cURL. The data posts correctly to Salesforce. However, the select multiple is not getting the correct values selected. See $sd["location"] below in my code:

//init curl
$ch = curl_init();
//setup the params
$url = '[URL]...';
$oid = "HIDDEN";
//setup the superdelegate array
$sd = array();
$sd["oid"] = $oid;............

The select multiple is already setup in Salesforce with a 30 different locations. I'm trying to pass the cities that should be selected (Chicago, New York, California).

View 3 Replies View Related

Populate Zend Form Select Element?

I have been searching for it from last couple of hours and have read every matching result google can give me but still can't get it to work.

I am creating a zend form select element through:

this->addElement('select','my_select', array(
'label' => 'Currency', 'value' => 'blue',
'multiOptions' => array( 'red' => 'Rouge', 'blue' => 'Bleu', 'white' => 'Blanc', ), ) );

now I want to populate it through

$form->populate

from the controller, I have tried giving double dimensional array like

$vals = array("my_select" => array("US Dollar", "Pound Sterling"))

and then giving it in:

$form->populate($vals);

but this didnt worked and I am not sure if this will work, at the moment I am building my array like in array( 'red' => 'Rouge', 'blue' => 'Bleu', 'white' => 'Blanc') the same class as zend form and then passsing it to the addElement multiOptions dynamically, here: [URL] that works but I would like to have it through populate

View 1 Replies View Related

Limit The Maximum Number Of HABTM And HasMany Records SAVED Per Parent Model In CakePHP?

I'm rebuilding one of my sites using the CakePHP Framework (awesome!), and I need to limit the number of hasMany and HABTM records that a Model can have. Let's say for "Profile hasMany Image," I want to limit a profile to only 10 images.

I know I can easily accomplish this using the Find method with 'count,' but I'm wondering if there's a property that can be set somewhere that I overlooked. I've looked at the CakePHP documentation and Googled a bit, haven't seen anything, but I'm always running across little CakePHP secrets now and then.

View 2 Replies View Related

Populate Form - Make Select List Sticky?

I am using the code below to populate a select list from fields in a db and it works great, the problem is how do I make it sticky? if the user types in the wrong info the page reloads and it does not remember what was selected from the list. I have tried a few different if statements but i couldn't get it working. The list populates with 15 customer names, what would be the best way to tackle this?

[Code...]

View 2 Replies View Related

Populate Form Select Options - Table Breaks When Add The <select> And It's Options?

I've got a table with 7 columns and I'm trying to populate one of the cells with an html select an it's options based on the results of the data row.The problem is as soon as I add the <select> and <options> it doesn't render the last three cells on the line where the condition is true.This link is not using the <select><option> stuff and table looks fine.

Link
Source of that file.

When the Category is == NONE I'm trying to get a select built as demonstrated here, but the last few cells on those rows do not get populated.

Link
Source of that file.

give the query a few seconds to run, it's kind of slow. why this table breaks as soon as I add the <select> and it's options.

View 1 Replies View Related

Select List - Edit Form

For a couple of days I have been trying to make an edit form that remembers the initial values a user entered. The edit.php page has a few textboxes and a few dropdown/select boxes. The textbox part works fine and comes from a database. Code:

View 7 Replies View Related

CakePHP Multiple Entry Fields With SaveAll() HABTM Multiple Records Insert Not Saving

Everything below IS working with the exception of my HABTM Zip data. Here is my code:

[Code....]

View 3 Replies View Related

Form Select Options - Populate The Options For The User To Pick With A List From A Database?

I have a Form control with a Select element. I want to populate the options for the user to pick with a list from a database. How do I get this into the Select Options? Is there a relatively simple way with HTML or is this a question for PHP?

View 3 Replies View Related

Populate A "Select" Box Drop Down Menu In A Form With Database Fields?

I am currently creating a form and I want to populate a drop down selection menu with data from two fields in a form. For example, I want it to pull the first and last name fields from a database to populate names in a drop down menu in a form. I want the form to submit to the email address of the person selected in the drop down. Is this possible to do? The email is already a field in the record of the person in the database.

how I should go about setting up the "Select" box drop down? I am not sure how to code it to do what I am wanting.

View 10 Replies View Related

Html - Populate A Second Select-tag With Options Based On The Option Selected In The First Select-tag?

I will draw the options for the second select-tag from a database.

View 4 Replies View Related

Populate Forms Edit Boxes

I have two simple text boxes in my <form> declaration On the same page I gave PHP code on top which is called from within tha same html portion of the page at the bottom.

Is there a way to dynamically populate the existing text box in the html part using code from the PHP part?

View 1 Replies View Related

Auto Populate Dropdown Without Having 'id' Field In CakePHP?

I have two tables:

countries with fields [objid(PK), name]
cities with fields [objid(PK), name, country_id(FK)]

Using cakePHP, what would be the correct syntax of using $belongsTo in city model to auto populate the countries drop down?

View 1 Replies View Related

CakePHP - Add To/edit $this->passedArgs?

multiple parameters being passed via the url-city, cuisine, features, and what page you're on (thank you paginator)If user is on page 2 -...index/page:2 and clicks on the city "New York", they should go to...index/page:2/city:New York.Then, if they then click on Houston, they should go to ...index/page:2/city:New York_Houston.Is there any easy/built in way to do that?I've started writing my code to break apart the $this->passedArgs, and rebuild it-but this has been a pain so far, and it seems like I'm writing a ton of code for something I'm hoping Cake has a way to handle.
Example:
User is on page 2 of a restaurants list - index/page:2
User clicks "New York", the page refreshes with index/page:2/city:New York
User clicks "San Diego" - the page refreshes with index/page:2/city:New York_San

[code]...

View 4 Replies View Related

CakePHP Edit Multiple Records At Once?

HABTM relationship between two tables:items and locations, using the table items_locations to join them.items_locations also stores a bit more information.Here's the schema

items_locations(id, location_id, item_id, quantity)

I'm trying to build a page which shows all the items in one location and lets the user, through a datagrid style interface, edit multiple fields at once:Location: Factory XYZ
___________________________
|___Item____|___Quantity___|
| Widget | 3 |
| Sprocket | 1 |
| Doohickey | 15 |
----------------------------
To help with this, I have a controller called InventoryController which has:
var $uses = array('Item', 'Location'); // should I add 'ItemsLocation'?How do I build a multidimensional form to edit this data?
Edit:I'm trying to get my data to look like how Deceze described it below but I'm having problems again.

// inventory_controller.php
function edit($locationId) {
$this->data = $this->Item->ItemsLocation->find(

[code]...

View 1 Replies View Related

Cakephp: Edit View Inserting Instead Of Updating?

If I have an edit view that is inserting a row instead of updating a row, what do I need to check?

The id of the row I'm editing is being passed in on the url:

http://localhost/cakepf/schedules/edit/78

Here are the contents of $this->data that are being passed into the edit controller function:

Array
(
[Schedule] => Array
(
[task_id] => 1
[repeat_type_id] => 10
[priority] =>
)
)

task_id and repeat_type_id are required; priority is not.

View 1 Replies View Related

Multi-record Edit With Related Data On Cakephp?

simple application with CakePhp,creating a multi-record edit form using some related data.The application I'm developing is pretty straightforward, its main purpose is managing students records:updating, deleting, changing a student from one group to another, the usual suspects.The relevant tables of the database are:

group = (id, teacher, classroom, etc)
groups_students=(groupID, studentID, since, until)
students = (id, name, last_name, etc)

[code]...

As you might have gathered from the tables above, the application is supposed to aid in recording assitance.Which is where I'm having some issues.What I want to do is this:Have the user select a group In de detail group, I'll have an action called "Register Assistance" Register assitance should redirect to a view in wich for every student belonging to that group, the user can see the student's assitance, edit them, and save.Something like this:In which A stands for "Absent" and P for "Present" and the user can edit everyone, and the save.

I just don't know how to go about that?How do I manage that?I've managed to create a multi-edit form for the assitance, but adding the related data is a pain, I don't know if I should query the students from the groups controllers and then pass that to the action to register assitance, or manage all the logic inside the assitance controller?

Edit: Here's the output of $this->Student->find('first');
Array (
[Alumno] => Array (
[id] => 14
[tipo] => dni

[code]...

The output is in spanish.Alumno = Student, nombre= first name, apellido= last_name.

View 1 Replies View Related

Can't Edit Other Table Information On A HasOne Relationship In CakePHP?

I have 2 tables liked in CakePHP app, one is Users which hasOne Profile liked to.I have managed to automatically create entries in both when creating a new user, but, when I try to edit everything in my user-edit page, it will create a new profile entry, causing my user to have 2 profiles linked to.Both models are perfectly coded and linked, as I said, I'm able to create a new user and the system automatically creates the profile and links it.Here is my user_controller.php with the edit function that is not working properly:

function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid User', true));
$this->redirect(array('action' => 'index'));

[code]...

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved